Skip to content

Fix ThreadLocal memory leaks in KSObjectCacheManager#2146

Merged
ting-yuan merged 1 commit into
google:mainfrom
kaeawc:kaeawc/fix-thread-local-memory-leaks
Oct 16, 2024
Merged

Fix ThreadLocal memory leaks in KSObjectCacheManager#2146
ting-yuan merged 1 commit into
google:mainfrom
kaeawc:kaeawc/fix-thread-local-memory-leaks

Conversation

@kaeawc

@kaeawc kaeawc commented Oct 12, 2024

Copy link
Copy Markdown
Contributor

Potentially fixes #2073, however unable to test against the project that reproduced the issue. I checked the other occurrences of ThreadLocal and the one mentioned in KSObjectCacheManager is the only one which seems it needs specific clearing and is clearly a culprit due to various users providing heap dumps across multiple JDK versions.

@kaeawc kaeawc changed the title upon clearing the ks object cache, clear retained thread locals Fix ThreadLocal memory leaks in KSObjectCacheManager Oct 12, 2024
@kaeawc

kaeawc commented Oct 15, 2024

Copy link
Copy Markdown
Contributor Author

I've been able to validate my fix by building KSP from source against Kotlin dev 5441, building Dagger (Hilt, the Hilt Android Gradle Plugin, and shading lib tools) against that local KSP and Kotlin dev 5441, and then building NowInAndroid against all of those in my local Maven repository. Here are the results observed via VisualVM

Before After
metaspace-before metaspace-after

@ting-yuan ting-yuan merged commit 00d6f42 into google:main Oct 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

KSP memory leak in Android build

5 participants