简体   繁体   English

Java:如何查找对特定类实例的所有引用

[英]Java: how to find all references to a specific class instance

I have a Java application where a specific object is the principal reason of RAM occupation, this is ok. 我有一个Java应用程序,其中特定对象是RAM占用的主要原因,这没关系。 Application logic has to drop this object instance and create a new one. 应用程序逻辑必须删除该对象实例并创建一个新的实例。 I suspect old instance is kept alive by some reference. 我怀疑某些实例可以使旧实例保留下来。

Is there a way to list all references of a specific class instance using Eclipse debug or anything else? 有没有一种方法可以使用Eclipse调试或其他方法列出特定类实例的所有引用?

Using Eclipse Memory Analyzer plugin (org.eclipse.mat.feature.feature.group): 使用Eclipse Memory Analyzer插件(org.eclipse.mat.feature.feature.group):

  • Run your application to the point where you suspect the memory leak 将应用程序运行到怀疑内存泄漏的位置
  • Open the Memory Analysis perspective in Eclipse 在Eclipse中打开Memory Analysis透视图
  • Click "Acquire Heap Dump" button in toolbar 单击工具栏中的“获取堆转储”按钮
    • Eclipse will need enough memory to process it, usually about the same amount as the application analyzed - you might need to change eclispe.ini to add more memory (if you don't have enough RAM you may instead create the memory dump using jvisualvm then close the app and start eclipse with increased -Xmx ) Eclipse将需要足够的内存来处理它,通常与所分析的应用程序的内存量相同-您可能需要更改eclispe.ini以添加更多的内存(如果没有足够的RAM,则可以使用jvisualvm创建内存转储,然后关闭应用程序,并使用增加的-Xmx开始eclipse)
  • Once the dump loads, you can browse it to identify the leak source (I don't recall details, but roughly - browse to your class, right click, view objects with incoming references) 转储加载后,您可以浏览它以标识泄漏源(我不记得详细信息,而是粗略地浏览到您的类,右键单击,查看带有传入引用的对象)

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

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