Skip to content

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

Merged
johnrengelman merged 1 commit intoGradleUp:masterfrom
mark-vieira:master
Nov 21, 2018
Merged

Avoid leaking plugin classes into Gradle's pattern spec result cache#430
johnrengelman merged 1 commit intoGradleUp:masterfrom
mark-vieira:master

Conversation

@mark-vieira
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Collaborator

This fix is now available in 4.0.3

@mark-vieira
Copy link
Copy Markdown
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