如何通过GC(垃圾收集器)将对象标记为垃圾收集? [英] How to mark an object for garbage collection by the GC (Garbage Collector)?

查看:65
本文介绍了如何通过GC(垃圾收集器)将对象标记为垃圾收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,是否有一种方法可以在下一个清理周期内,为GC标记 对象以进行垃圾回收?

In Java, is there a way to mark an object for garbage collection by the GC, during its next clean up cycle?

我听说将对象设置为null不再起作用.

I've heard that setting an 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天全站免登陆