简体   繁体   English

从Java堆收集旧对象

[英]Collecting old objects from java heap

I have Order_Item class instance, and these are paths to GC Roots (excluding phantom/weak/soft references): 我有Order_Item类实例,这些是GC根目录的路径(不包括幻像/弱引用/软引用): 在此输入图像描述

I have few questions: 我有几个问题:
1) I'm not sure if the Order_Item will be garbage collected. 1)我不确定Order_Item是否将被垃圾回收。
I tried to run System.gc(), and the object remained in heap. 我试图运行System.gc(),并且该对象保留在堆中。
Is it allowed to be collected, according to provided image? 根据提供的图像,是否可以收集它?

2) What "Native Stack" mean? 2)“本地堆栈”是什么意思? As far as I understood, it's accounted as GC root. 据我了解,它是GC根目录。 http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Fconcepts%2Fgcroots.html Why some object (ie Order 0x782032cf8) is kept in "Native Stack"? http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.mat.ui.help%2Fconcepts%2Fgcroots.html为什么某些对象(例如,订单0x782032cf8)保留在“本机堆栈”中?

3) If I have reference from GC Root to object A, that object will not be garbage collected? 3)如果我从GC根目录引用了对象A,该对象将不会被垃圾收集? Right? 对?
And if so, my Order_Item object can't be garbage collected? 如果是这样,我的Order_Item对象无法被垃圾回收吗?

4) If 3 is right, how may I find what keeps objects 0x7821da5e0 and 0x782032cf8, and how to dereference/remove them? 4)如果3是正确的,我如何找到保持对象0x7821da5e0和0x782032cf8的对象,以及如何取消引用/删除它们?

You cannot really force the garbage collector to delete a given object. 您不能真正强制垃圾收集器删除给定的对象。 You know that the object is kept alive as long as it is reachable by references from the given point in the program. 您知道,只要程序中给定点的引用可以访问该对象,该对象就会保持活动状态。 But if the object gets "collectable", it might be collected soon, but if there is no pressure on memory, it may fool around for a long time. 但是,如果对象变为“可收集”的,则可能会很快对其进行收集,但是如果对内存没有压力,它可能会在很长一段时间内四处闲逛。

Usually, there is not reason to really delete objects if there is enough memory. 通常,如果有足够的内存,则没有理由真正删除对象。 The only exception I know are passwords. 我知道的唯一例外是密码。 Here, you use a char array and overwrite it with nonsense once you used it. 在这里,您使用char数组,并在使用后用废话覆盖它。

For the native stack: Your link indicates that the native stack keeps external resources, eg files. 对于本机堆栈:您的链接指示本机堆栈保留外部资源,例如文件。

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

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