In Java, allocation and deallocation of heap memory are handled by
the virtual machine, i.e., by its memory manager and its garbage collector.
This concept frees developers from the chores of explicit memory allocation
and deallocation and eliminates the pitfalls that explicit memory management
comes with, e.g. there are no memory leaks or dangling pointers in Java.
Despite of this undeniable benefit, Java programs occasionally exhibit
performance defects that are caused by excessive memory allocation or massive
and time-consuming garbage collection. In order to eliminate these
adverse effects on the program's overall performance, a Java developer
needs an understanding of the memory allocation and garbage collection
strategies of the JVM.
The tutorial gives an overview of various garbage collection algorithms
employed by the Java virtual machine of Sun's JDK 6 including tips and
tricks for tuning the garbage collector, use of memory profilers and garbage
collection profilers. We will also briefly touch on escape analysis,
which is an optimization technique used by the JVM to completely eliminate
heap memory allocation and deallocation for certain objects.
garbage collection principles and algorithms
mark-and-sweep, fragmentation and compaction
parallel, concurrent and incremental GC
memory allocation an escape analysis
heap objects vs. stack objects
detection of unwanted references and loitering objects
GC profiling tools
GC tuning options