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

Avoid leaking plugin classes into Gradle's pattern spec result cache #430

Merged
merged 1 commit into from
Nov 21, 2018

Conversation

mark-vieira
Copy link
Contributor

This pull request fixes some memory leak issues we noticed when using the Shadow plugin with long lived Gradle daemons. The commit addresses two items:

  1. RelativeArchivePath was unnecessarily keeping a reference to DefaultFileCopyDetails which is a pretty heavyweight object. Turns out this is never actually used so this has been removed.

  2. The whole reason item (1) was an issue was is because results of calls to pattern specs are actually cached by Gradle, such as this one. The cache computes a key based on this RelativeArchivePath, therefore instances of those stay in memory. Making those instances lighter (by removing the reference to FileCopyDetails) helps here but the root cause is that the daemon keeps strong references back to plugin classes, and therefore, their classloader. When changes to buildSrc happen these old classloaders pile up, as we cannot garbage collect them due to these cache references. The solution here is to not use non-core types in these caches at all, thus the addition of getAsFileTreeElement() to ArchiveFileTreeElement. This avoids the need to pass ArchiveFileTreeElement directly to isSatisfiedBy() and thereby ensuring no classes from this plugin leak into the pattern set result caches.

@johnrengelman
Copy link
Collaborator

Thank you for the digging into this and providing the fix @mark-vieira !

@johnrengelman johnrengelman merged commit e4166d0 into GradleUp:master Nov 21, 2018
@johnrengelman
Copy link
Collaborator

This fix is now available in 4.0.3

@mark-vieira
Copy link
Contributor Author

Awesome. Thanks for the quick turnaround.

@johnrengelman johnrengelman added this to the 4.0.3 milestone Nov 21, 2018
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.

2 participants