Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ThreadLocal memory leaks in KSObjectCacheManager #2146

Merged
merged 1 commit into from
Oct 16, 2024

Conversation

kaeawc
Copy link
Contributor

@kaeawc kaeawc commented Oct 12, 2024

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
Copy link
Contributor Author

kaeawc commented Oct 15, 2024

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
3 checks passed
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