简体   繁体   中英

visualVM memory leak

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM