简体   繁体   English

视觉VM内存泄漏

[英]visualVM memory leak

While using visualVM to detect memory leak, it allows us an Instance view as described below:在使用visualVM检测内存泄漏时,它允许我们使用如下所述的实例视图:

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.当您从“实例”窗格中选择一个实例时,VisualVM 会在相应的窗格中显示该类的字段以及对该类的引用。 In the References pane, you can right-click an item and choose Show Nearest GC Root to display the nearest garbage collection root object.在 References 窗格中,您可以右键单击一个项目并选择 Show Nearest GC Root 以显示最近的垃圾回收根对象。

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:您可能会发现有关垃圾收集的 Sun 书籍/章节很有用,尤其是将 GC 根目录列为的这一节

  • Temporary variables on the stack (of any thread)堆栈上的临时变量(任何线程的)
  • Static variables (from any class)静态变量(来自任何类)
  • Special references from JNI native code来自 JNI 本机代码的特殊引用

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.换句话说,GC 根是变量,可以通过根持有对它的引用来防止另一个对象被 GC。

A GC root is a reference held in a static or local variable. GC 根是保存在静态或局部变量中的引用。 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.在 VisualVM 中,您可以使用“显示最近的 GC 根”功能来帮助您跟踪对您认为应该进行垃圾回收的对象的引用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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