至少NetBeans使用System.gc():
http://hg.netbeans.org/main/annotate/9779f138a9c9/openide.actions/src/org/openide/actions/GarbageCollectAction.java(这是显示当前堆的小按钮,允许您启动GC)。如果您关注该链接,您会看到他们明确地运行终结器。如果你有一些免费的磁盘空间,并想自己调查代码,可以通过Mercurial获得:hg clone http://hg.netbeans.org/main/
据我所知,“System.gc()只是一个暗示”教条起源于对JLS和JVM规范的迂腐解释,它允许Java实现没有垃圾收集堆。那,以及对JavaDoc的不完整阅读:
Calling the gc method suggests that
the Java Virtual Machine expend effort
toward recycling unused objects in
order to make the memory they
currently occupy available for quick
reuse. When control returns from the
method call, the Java Virtual Machine
has made a best effort to reclaim
space from all discarded objects.
阅读第二句话:“尽力回收空间”比“提示”强很多。
也就是说,很少有理由调用System.gc()。向Knuth道歉:
We should forget about memory management, say about 97% of the time: explicit garbage collection is the root of all evil
博客介绍了NetBeans使用System.gc()的情况,还提到‘System.gc()只是一个暗示’教条的起源,源于对JLS、JVM规范的迂腐解释和对JavaDoc的不完整阅读。同时指出阅读JavaDoc可知‘尽力回收空间’比‘提示’更强,且很少有理由调用System.gc()。
14万+

被折叠的 条评论
为什么被折叠?



