在GC中标记要删除的对象 [英] Marking an Object To Be Removed In The GC

查看:133
本文介绍了在GC中标记要删除的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可以在java中标记一个对象来进行下次清理时垃圾回收?

Is there away that I can mark an object, in java, to be garbage collected for the next time it cleans up?

我听说将对象设置为null不再有效。

I've heard that setting the object to null no longer works.

推荐答案

我知道这个问题已经得到解答,但您可以通过多种方式来操作Java垃圾收集器查看您的方式引用。您可以通过软参考,弱参考和幻影参考来做到这一点。查看java.lang.ref包以获得更好的解释。

I know this question has been answered, but there are ways you can manipulate the way that the Java Garbage collector looks at your references. You can do this through Soft References, Weak References, and Phantom References. Take a look at the java.lang.ref package for a better explanation.

http://download.oracle.com/javase/1.5.0/docs/api/java/lang/ref/ package-summary.html

此处还有一个很好的示例,用于确定PhantomReference何时将被垃圾收集。

Also here's a nice sample to determine when a PhantomReference is about to be garbage collected.

http://exampledepot.8waytrips.com/egs /java.lang.ref/PhantomRef.html

以下是它的主要网站:

http://exampledepot.8waytrips.com/

这篇关于在GC中标记要删除的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆