Garbage Collection On DemandIn 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.
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.
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)