Every time gradle is run, for our build the daemon leaks about 100m of memory.
This would be perfectly acceptable if the daemon would die quickly when it exhausts the heap, but what actually happens is that from watching -verbose:gc, we see the daemon doing 1+ second full GCs nearly back-to-back, and the builds using the daemon slow down by 2x or more. I can run several more builds that take 10 seconds when the daemon is not in this thrashing mode, and the builds take over a minute, and the daemon won’t die for several minutes, when I’d prefer it die and restart much sooner to avoid repeatedly building very slowly.
In an attempt to configure JVM options to automatically kill the daemon promptly, I tried various values of the GC overhead limit options, e.g. -XX:+UseGCOverheadLimit -XX:GCTimeLimit=10 -XX:GCHeapFreeLimit=10. (I may have misread the option documentation and those values may not be useful.)
I tried CMS, the default GC, and G1GC on version:
java -version java version “1.7.0_40” Java™ SE Runtime Environment (build 1.7.0_40-b43) Java HotSpot™ 64-Bit Server VM (build 24.0-b56, mixed mode) and all GCs went into full GC thrash mode with slow builds instead of dying promptly.
If this is a problem without a current solution, I have some simplistic ideas about code that may help, e.g. have a parameter like killIfRemainingFreeMemoryLessThan, and a thread would kill the daemon if free memory was less than that value for N consecutive samples over a configurable sampling interval. (The idea being to ignore low memory if a GC reclaims it.) In my case, I would configuer this to die if the heap had less than 100m or 200m free, for a -xmx of 2 or more GB.
If you need more information, I can generate images of jvisualVM, provide GC logs, or whatever will help. Thanks.