我可以在Java中强制垃圾回收吗? [英] Can I Force Garbage Collection in Java?

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

问题描述


可能存在重复:

在Java中强制垃圾回收?


我可以强制垃圾以任何方式收集Java?

System.gc()只是一个建议。它没用。

当我确定某些资源不再被使用时,为什么我不能强制清除它们?



就像C ++中的delete()和free ()in C?



当有很多资源不能被重用时,这可能真的吸引了性能。我们所能做的就是sleep()。



任何解决方案?谢谢 解决方案



也就是说,如果你在unix盒子上,强制线程转储(kill - 3),它会非常强制垃圾回收。


Possible Duplicate:
Forcing Garbage Collection in Java?

Can I Force Garbage Collection in Java by any means?

System.gc() is just a suggestion.It's useless.

When I know for sure that some resources won't be used any more,why can't I force to clean them?

Just like delete() in C++ and free() in C?

When there are lots of resources that can't be reused,this can really suck the performance.All that we can do is sleep().

Any solutions?Thanks

解决方案

Nope, System.gc() is as close as you can get. Java isn't C or C++, the JVM manages memory for you, so you don't have that kind of fine grained control. If you set objects you're no longer using to null, or loose all references, they will get cleaned up. And the GC is pretty smart, so it should take good care of you.

That said, if you are on a unix box, and force a thread dump (kill -3), it'll pretty much force garbage collection.

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

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