Java: Memory

Java: Memory,第1张

Java: Memory Garbage Collection

In Java, the memory created on the heap is released by the garbage collector. When no references to an object exist, that object is assumed to be no longer needed, and the memory occupied by the object can be reclaimed. There is no explicit need to destroy objects as in C++. Garbage collection only occurs sporadically (if at all) during the execution of your program. It will not occur simply because one or more objects exist that are no longer used.

Garbage Collection On Demand

If instead of running garbage collector sporadically, you want to invoke the mechanism yourself you can do --

    Runtime r = Runtime.getRuntime();
    r.gc(); // request garbage collection
    r.freeMemory(); // get baseline memory usage.

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4873736.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-11
下一篇 2022-11-11

发表评论

登录后才能评论

评论列表(0条)

保存