Memory leaks in Java and JVM GC (garbage collection)

First, what is a memory leak in Java?

  In Java, memory leaks is to some objects are allocated, these objects have the following two characteristics,

  First, these objects are reachable , i.e. a directed graph, the presence of passage may be connected thereto ; secondly, these objects are useless , i.e. objects not use these programs later .

  If the object is to satisfy these two conditions, these objects can be determined that the memory leaks in Java, these objects will not be recovered GC, but it does take up memory.

 

  In C ++, broader number of memory leaks. Some objects are allocated memory space, then do not reach, since C ++ does not GC, the memory will always be retrieved.

  In Java, these unreachable objects by GC responsible for recycling , so that programmers need not consider this part of the memory leak.

  Through analysis, we know that, for C ++, programmers need to manage the edges and vertices, and for Java programmers only need to manage edge on it (no need to manage the release of vertices).

  In this way, Java improve the efficiency of programming.

 

Guess you like

Origin www.cnblogs.com/mww-NOTCOPY/p/11683303.html