问题描述
java会将垃圾签名的东西收集为对象吗?
Does java collect the garbage-signed things as objects?
如果是,我可以告诉Java以编程方式将它们定向到我的哈希表之一(接受对象正确吗?)?
If yes, can i tell java to direct them to one of my hashtables(accepts objects right?) programmatically?
我对此功能很好奇.我知道System.gc()
是命令,但是我该如何解决第一个问题?我可以吗?
I am curious about this functionality.I know System.gc()
is the command but how can i achieve first question? Can i?
myTrashBin=System.gc().getObjectList(); //???
如果没有,也许可以通过自定义类来创建此功能.
If not, may be there could be a way to create this functionality by custom classes.
最后一个问题:我们如何覆盖System.gc()?
Last question: how can we override System.gc() ?
谢谢.
推荐答案
这不受您的控制.如果无法访问您的对象,则GC将收集这些对象. System.gc()
只是一个提示,不能被依赖.
This isn't under your control. If your objects are unreachable then GC will collect these. System.gc()
is nothing more than a hint, and can't be relied upon.
finalize()
可能很有趣,但请阅读此问题的答案以了解限制等. PhantomReferences 可能也很有趣.
finalize()
may be of interest, but read the answers to this question to understand limitations etc. PhantomReferences may also be of interest.
这篇关于Java垃圾收集到哈希表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!