Skip to content

Conversation

mrdziuban
Copy link
Contributor

Fixes sbt/sbt#8150

In #563, I chose to wrap the cache map's values in WeakReference because in heap dumps I was seeing a lot of sbt.librarymanagement.Artifact and sbt.librarymanagement.ModuleIDs mentioned as values that SbtUpdateReport was referencing. Using WeakReference caused them to go away.

The result of using it is that the map's values could be garbage collected before its keys, leading to map entries with null values and causing NullPointerExceptions.

Looking more closely at the heap dumps, I don't think the Artifacts and ModuleIDs are part of the original memory leak issue, so it should be fine to remove WeakReference. Without WeakReference the number of them doesn't grow linearly with the number of updates, nor does the retained heap of SbtUpdateReport.

@eed3si9n do you mind taking a look?

@eed3si9n eed3si9n merged commit 8c311c8 into coursier:main Jun 2, 2025
9 checks passed
@mrdziuban mrdziuban deleted the weak-hash-map branch June 2, 2025 14:33
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.

NullPointerException since sbt 1.11.1
2 participants