java gc强制_Java:你如何使用JVMTI的ForceGargabeCollection强制GC?

至少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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值