Databases Reference
In-Depth Information
Some Java objects are short lived, such as local variables; others are long-
lived, such as connections. Generational garbage collection divides the heap into
Young and Old generations, as shown in Figure 4-4. New objects are allocated
from the Young generation and, if they live long enough, eventually migrate to
the Old generation. Figure 4-4 also shows another generation called the
Permanent generation, which holds the JVM's class and method objects.
Perm
Old
Young
Memory for Objects Created by Your Application
Total Heap Size
Figure 4-4
Heap generations
When the Young generation becomes full, the garbage collector looks for
surviving objects while cleaning up short-lived objects. It moves surviving
objects into a reserved area of the Young generation called a survivor space. If
that survivor is still being used by the next collection, it's considered tenured. In
this case, the collector moves the object into the Old generation. When the Old
generation becomes full, the garbage collector cleans up any unused objects.
Because the Young generation typically occupies a smaller heap space than the
Old generation, garbage collection occurs more frequently in the Young genera-
tion, but collection pauses are shorter.
Similar to the way that the overall heap size affects garbage collection, the
heap sizes of the generations affect garbage collection.
Performance Tip
As a general rule, set the size of the Young generation to be one-fourth
that of the Old generation. You may want to increase the size of the
Young generation if your application generates large numbers of short-
lived objects.
Different JVMs use different garbage collection algorithms. A few let you tune
which algorithm is used. Each algorithm has its own performance implications.
Search WWH ::




Custom Search