Java: Memory

wuchangjian2021-10-31 07:14:55编程学习

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.

相关文章

HDFS读数据流程

HDFS读数据流程

1.与NameNode通信查询元数据,找到文件块所在的DataNode...

学习Java的第一周

        面向对象: 类是对一类事...

数据结构与算法自学8

2021/11/11 大话数据结构 赫夫曼树定义及原理 赫夫曼编码 图 无...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。