There are at least two ways, directly or indirectly, to suggest that the JVM spends efforts to collect garbage:
System.gc()- dropping heap and querying only live objects
In the latter case, I can get a bunch of dump programmatically, for example, through
hotspotMBean = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), "com.sun.management:type=HotSpotDiagnostic", HotSpotDiagnosticMXBean.class);
hotspotMBean.dumpHeap(filename, live);
What is the difference, if any, between what these two operations will do to collect objects that are not able to achieve?
I believe that I have evidence that the heap dump approach is more aggressive than System.gc()with some combination of weak references, distributed RMI garbage collection, and invisible objects are highly reachable from the stack . In particular, objects that are only weakly accessible locally and become Unreferencedrelative to RMI are apparently only collected using a dump heap. I have not yet been able to remake this into a small test case, but it is reproducible.
(Before I am warned against relying on the specific behavior of the GC in the prod code, I donβt know. I discovered this by examining a potential memory leak and noticed that the result changed depending on when I took the heap heap. ' just curious.)
Windows 7 uses the 64-bit server version of HotSpot 1.6.0_22.