我可以在Java中强制垃圾回收吗?

编程入门 行业动态 更新时间:2024-10-15 04:19:21
本文介绍了我可以在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中强制垃圾回收吗?

本文发布于:2023-10-31 13:49:19,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:垃圾   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!