Search code examples
javamemory-leaksgarbage-collectionjprofilermemory-profiling

JProfiler: how to display surviving generations aka generations count?


Some talks on finding Java memory leaks (one, two) suggest using the surviving generations metric to identify the classes whose instances remain live after multiple GC events and thus can constitute a memory leak.

Is it possible to see this metric in JProfiler when viewing live or recorded objects?

In JProfiler 13.0.6 I searched both the All Objects and Recorded Objects views, and their respective Vew Settings dialogues, but couldn't find any such option.


Solution

  • It is not possible to ask the JDK which generation an object is in, the tool interface (JVMTI) does not provide information about the garbage collector. The only available information is the statistics that is published by the garbage collector.

    In JProfiler, you can use the "Mark heap" action that is advertised on the heap walker overview and that is also available in the Profiling menu or as a trigger action. It marks all objects on the heap as "old". When you take the next heap snapshot, it is now shown how many new objects there are and you can select the old objects with a single click.