Basic Garbase Collection

In trying to resolve an issue with my existing project (what appears to be an intermittent bug), I’ve been forced to consider and understand some deeper follicles of the Garbage Collector *grunt* (in this case, Java)

So it appears that most distribution of objects across the life of an application have what appear to be a more or less consistent normative curse (the one above).
As such, within this distribution, the life of objects are more less determined and it is this concept, that forms the algorithm for the garbage collector.

Garbage collection occurs in generations, that is, the garbage collector cleans up when the generation fills up.
Object are allocated into generations. When the young generation fills up, it causes a minor collection.
Minor collection can be optimized assuming a  high infant mortality rate.
A young generation full of dead objects is collected very quickly. Some surviving objects are moved to the tenured generation.
When the tenured generation is collected, there is a major collection (this is often slow because it contains live objects).

I know this sounds obvious, but tuning of the Garbage collector should only become necessary when the garbage collector is a bottleneck.

At virtualization, a maximum address space is virtually reserved but not allocated to physical memory (unless it is needed).
The complete object memory can be divided into the young and tenured generations.

The young generation consists of “eden” plus two survivor spaces. Objects are initially allocated in eden.
You might have seen this before:

SPAN { font-family: “Courier New”; font-size: 10pt; color: #000000; background: #FFFFFF; }A { text-decoration: none; font-weight: bold; color:#000000;}Heap
def new generation total 960K, used 305K [0x22990000, 0x22a90000, 0x22e70000)
eden space 896K, 32% used [0x22990000, 0x229d9df8, 0x22a70000)
from space 64K, 15% used [0x22a70000, 0x22a72828, 0x22a80000)
to space 64K, 0% used [0x22a80000, 0x22a80000, 0x22a90000)
tenured generation total 4096K, used 3365K [0x22e70000, 0x23270000, 0x26990000)
the space 4096K, 82% used [0x22e70000, 0x231b9760, 0x231b9800, 0x23270000)
compacting perm gen total 12288K, used 5241K [0x26990000, 0x27590000, 0x2a990000)
the space 12288K, 42% used [0x26990000, 0x26eae7f0, 0x26eae800, 0x27590000)
ro space 8192K, 63% used [0x2a990000, 0x2aea8810, 0x2aea8a00, 0x2b190000)
rw space 12288K, 53% used [0x2b190000, 0x2b7fd300, 0x2b7fd400, 0x2bd90000)

Objects are copied between survivor spaces in this way until they old enough to be tenured.
I think that’s enough for now!

Don't be shellfish...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on TumblrEmail this to someone

Leave a Reply