Garbage collection Garbage Collection

GC role:
1. Discover useless objects
2. reclaim the space occupied by useless objects
 
So how do you find out if an object GC useless it?
A reference counting method
Each object has a reference count, a reference is, count is incremented, the reference variable value becomes null, the count is decremented until the count is 0, then becomes useless objects, the advantage of a simple algorithm, the disadvantage is useless objects does not recognize circular references
Second, the reference up method (root search method)
 After the program all references to the relationship seen as a map from a node GC ROOT start, find the corresponding reference node, find the node, the node continue to look for a reference node, when all the reference nodes looking for is completed, the remaining nodes node is considered not to be quoted, be recovered
 
Common generational garbage collection
Generational garbage collection mechanism is based on the fact: the life cycle of different objects is not the same, therefore, objects of different life cycle can take different recovery algorithms, in order to improve the recovery efficiency, we were divided into three states : the young generation, old generation, lasting generations. JVM memory is divided into
Edern, Survivor, Old space. Persistent behalf of that type of information, or that the code exists, it exists. In the process of permanent generation area, and the young generation in Edern space, the old generation in the Old space.
 
When Edern space is full, you can not create new objects and trigger a garbage collection mechanism in the Minor GC, use reference counting or reference up to remove unwanted objects, then the object within the space Edern full copy to Survivor1, Survivor2 space (which two spaces of the same size, the same time only one is empty, with a). And then create a new object to Edern space, constantly repeated. Later Survivor2 full, its copy to the Old space, full of attention Survivor district does not trigger GC. But when Old space is full, it will start Major GC, when all spaces are full, will start the Full GC, used to clean up the young generation, old generation area. Higher costs, have an impact on system performance.
 
Full GC JVM tuning and
In the process of tuning the JVM, a large part of the work is adjusted to the Full GC (avoid Full GC) has the following possible causes of call full GC:
1. The old generation is filled
2. The permanent generation is filled
3.System.gc () call is displayed ( program recommended GC start, instead of calling GC)
4. Dynamic changes the previous generation by GC after each domain Heap allocation strategy
 
Development is likely to cause a memory leak operation
 
 
 
 
 
 
 
 
 

Guess you like

Origin www.cnblogs.com/Kundalini/p/11707800.html