While using visualVM to detect memory leak, it allows us an Instance view as described below:
The Instance view displays object instances for a selected class. When you select an instance from the Instance pane, VisualVM displays the fields of that class and references to that class in the respective panes. In the References pane, you can right-click an item and choose Show Nearest GC Root to display the nearest garbage collection root object.
Can anybody tell me what the nearest garbage collection root object is and how to make use of this information to help identify the leaking spots. Thanks!
You might find this Sun book/chapter on Garbage Collection useful, in particular this section which lists GC root as:
- Temporary variables on the stack (of any thread)
- Static variables (from any class)
- Special references from JNI native code
In other words, GC roots are variables that can keep another object from being GCed by virtue of the root holding a reference to it.
A GC root is a reference held in a static or local variable. A reference held in a root prevents the referenced object from being garbage collected.
In VisualVM you can use the "show nearest GC root" feature to help you track down references to the object that you believe should be garbage collected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With