A garbage collector is responsible for
• allocating memory
• ensuring that any referenced objects remain in memory, and
• recovering memory used by objects that are no longer reachable
from references in executing code.
Objects that are referenced are said to be live. Objects that
are no longer referenced are considered dead and are termed garbage. The
process of finding and freeing (also known as reclaiming) the space used by
these objects is known as garbage collection.
Garbage collection solves many, but not all, memory allocation
problems. You could, for example, create objects indefinitely and continue
referencing them until there is no more memory available. Garbage collection is
also a complex task taking time and resources of its own.
The precise algorithm used to organize memory and allocate and
deallocate space is handled by the garbage collector and hidden from the
programmer. Space is commonly allocated from a large pool of memory referred to
as the heap.
The timing of garbage collection is up to the garbage collector.
Typically, the entire heap or a subpart of it is collected either when it fills
up or when it reaches a threshold percentage of occupancy.
The task of fulfilling an allocation request, which involves
finding a block of unused memory of a certain size in the heap, is a difficult
one.
We have already discussed regarding the Java Heap Memory Sizing
in my previous posts, moving ahead lets discuss regarding the Java Garbage
Collector Sizing for Hyperion Applications in Windows and Linux
Before you start to tune the command line arguments for Java be
aware that Sun’s HotSpot™ Java Virtual Machine has incorporated technology to
begin to tune itself. This smart tuning is referred to as Ergonomics.
Most computers that have at least 2 CPU’s and at least 2 GB of physical memory
are considered server-class machines
which means that by default the settings are:
·
The -server compiler
·
The -XX:+UseParallelGC parallel (throughput) garbage
collector
·
The -Xms initial heap size is 1/64th of the machine’s
physical memory
·
The -Xmx maximum heap size is 1/4th of the machine’s
physical memory (up to 1 GB max).
Please note that 32-bit Windows systems all use
the -client compiler by default and 64-bit Windows systems which meet
the criteria above will be be treated as server-class machines.
Garbage Collector Policy
The Java™ Platform offers a choice of Garbage Collection algorithms. For each of these algorithms there are various policy tunables. Instead of repeating the details of the Tuning Garbage Collection document here suffice it to say that first two choices are most common for large server applications:
The Java™ Platform offers a choice of Garbage Collection algorithms. For each of these algorithms there are various policy tunables. Instead of repeating the details of the Tuning Garbage Collection document here suffice it to say that first two choices are most common for large server applications:
·
The -XX:+UseParallelGC parallel (throughput) garbage
collector, or
·
The -XX:+UseConcMarkSweepGC concurrent (low pause
time) garbage collector (also known as CMS)
·
The -XX:+UseSerialGC serial garbage collector (for
smaller applications and systems)
For more
details please refer : http://www.oracle.com/technetwork/java/gc-tuning-5-138395.html