如何在Java中强制垃圾收集? [英] How to force garbage collection in Java?

查看:215
本文介绍了如何在Java中强制垃圾收集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能在Java中强制进行垃圾收集,即使这样做很棘手?我知道 System.gc(); Runtime.gc(); 但他们只是建议做GC。如何强制GC?

Is it possible to force garbage collection in Java, even if it is tricky to do? I know about System.gc(); and Runtime.gc(); but they only suggest to do GC. How can I force GC?

推荐答案

您最好的选择是调用 System.gc() 这仅仅是垃圾收集器的一个提示,您希望它执行收集。没有办法 force 和立即收集,因为垃圾收集器是非确定性的。

Your best option is to call System.gc() which simply is a hint to the garbage collector that you want it to do a collection. There is no way to force and immediate collection though as the garbage collector is non-deterministic.

这篇关于如何在Java中强制垃圾收集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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