When are isolated workers classloaders garbage col...
# community-support
m
When are isolated workers classloaders garbage collected?
Copy code
// This creates a new classloader, is it GC'd at the end of the work if nothing else keeps a reference?
      val workQueue = getWorkerExecutor().classLoaderIsolation { workerSpec ->
        workerSpec.classpath.from(classpath)
      }
This is the path to the nearest GC-root. Am I doing something stupid that prevents that classloader to be GC'd?
a
I think you are hitting something like https://github.com/gradle/gradle/issues/18313. They get GCed after next build afaik. It's a bug or at least something that needs an improvement
πŸ‘€ 1
m
Thanks! They keep adding up though so looks like I have another leak.... In heap dumps, I can see some classloaders have no GC root but are still around πŸ€”
Turns out moving to process isolation fixes the issue
πŸ‘ 1
a
Process isolation doesn't have this problem since classes are loaded in a different process and process stops after the build
m
Yea I guess it’s just a workaround... Still curious what the real issue is
a
From internal conversation:
Classloader reuse for classloader isolation has always been something that we planned to implement, but was de-prioritized before we got around to it. The caching of the generated work classes was added later and it seems it was never clear the effect this had on these classloader isolated work items. This creates the worst of both worlds (i.e. caching stuff that is never reused).
So basically there is some caching involved to reuse classloaders, but it's not effective and have negative consequences.
πŸ™ 1
m
For now, I'll expose the option to the user but it's not great as they have to choose between memory leaks or longer fork times.