SlideShare a Scribd company logo
5
Most read
6
Most read
9
Most read
GARBAGE COLLECTOR
Automatic garbage collection is the process of looking at heap memory,
identifying which objects are in use and which are not, and deleting the unused
objects. An in use object, or a referenced object, means that some part of your
program still maintains a pointer to that object. An unused object, or
unreferenced object, is no longer referenced by any part of your program. So the
memory used by an unreferenced object can be reclaimed.
In a programming language like C, allocating and deallocating memory is a
manual process. In Java, process of deallocating memory is handled
automatically by the garbage collector.
The basic process can be described as follows:
โ— Step 1: Marking
The first step in the process is called marking. This is where the garbage
collector identifies which pieces of memory are in use and which are not.
Referenced objects are shown in blue. Unreferenced objects are shown in
gold. All objects are scanned in the marking phase to make this
determination. This can be a very time consuming process if all objects in a
system must be scanned.
Step 2: Normal Deletion
Normal deletion removes unreferenced objects leaving
referenced objects and pointers to free space.
The memory allocator holds references to blocks of free
space where new object can be allocated.
Step 2a: Deletion with Compacting
To further improve performance, in addition to deleting
unreferenced objects, you can also compact the remaining
referenced objects. By moving referenced object together,
this makes new memory allocation much easier and faster.
Why Generational Garbage Collection?
โ— As stated earlier, having to mark and compact all the objects in a JVM is inefficient. As more and more
objects are allocated, the list of objects grows and grows leading to longer and longer garbage collection
time. However, empirical analysis of applications has shown that most objects are short lived.
JVM Generations
โ— The information learned from the object allocation behavior can be used to enhance the performance of
the JVM. Therefore, the heap is broken up into smaller parts or generations. The heap parts are:
Young Generation,
Old or Tenured Generation
Permanent Generation
โ— The Young Generation is where all new objects are allocated and aged. When the young generation fills
up, this causes a minor garbage collection. Minor collections can be optimized assuming a high object
mortality rate. A young generation full of dead objects is collected very quickly. Some surviving objects are
aged and eventually move to the old generation.
โ— Stop the World Event - All minor garbage collections are "Stop the World" events. This
means that all application threads are stopped until the operation completes. Minor
garbage collections are always Stop the World events.
โ— The Old Generation is used to store long surviving objects. Typically, a threshold is
set for young generation object and when that age is met, the object gets moved to the
old generation. Eventually the old generation needs to be collected. This event is called a
major garbage collection.
โ— Major garbage collection are also Stop the World events. Often a major collection is
much slower because it involves all live objects. So for Responsive applications,
major garbage collections should be minimized. Also note, that the length of the Stop the
World event for a major garbage collection is affected by the kind of garbage collector
that is used for the old generation space.
โ— The Permanent generation contains metadata required by the JVM to describe the
classes and methods used in the application. The permanent generation is
populated by the JVM at runtime based on classes in use by the application. In
addition, Java SE library classes and methods may be stored here.
โ— Classes may get collected (unloaded) if the JVM finds they are no longer needed and
space may be needed for other classes. The permanent generation is included in a full
garbage collection.
The pictures that follow walks through the object
allocation and aging process in the JVM:
First, any new objects are allocated to the eden space.
Both survivor spaces start out empty.
When the eden space fills up, a minor garbage collection
is triggered.
โ— Referenced objects are moved to the first survivor space.
Unreferenced objects are deleted when the eden space is
cleared.
โ— At the next minor GC, the same thing happens for the eden space.
Unreferenced objects are deleted and referenced objects are moved to a
survivor space. However, in this case, they are moved to the second survivor
space (S1). In addition, objects from the last minor GC on the first survivor
space (S0) have their age incremented and get moved to S1. Once all
surviving objects have been moved to S1, both S0 and eden are cleared.
Notice we now have differently aged object in the survivor space.
โ— At the next minor GC, the same process repeats. However this
time the survivor spaces switch. Referenced objects are moved
to S0. Surviving objects are aged. Eden and S1 are cleared.
โ— This slide demonstrates promotion. After a minor GC, when
aged objects reach a certain age threshold (8 in this example)
they are promoted from young generation to old generation.
โ— As minor GCs continue to occure objects will continue to
be promoted to the old generation space.
โ— So that pretty much covers the entire process with the
young generation. Eventually, a major GC will be
performed on the old generation which cleans up and
compacts that space.
Garbage collection
Common Heap Related Switches
There are many different command line switches that can be used with Java.
Switch Description
-Xms Sets the initial heap size for when the JVM starts.
-Xmx Sets the maximum heap size.
-Xmn Sets the size of the Young Generation.
-XX:PermSize Sets the starting size of the Permanent Generation.
-XX:MaxPermSize Sets the maximum size of the Permanent Generation
The Serial GC
The serial collector is the default for client style machines in Java SE 5 and 6.
With the serial collector, both minor and major garbage collections are done
serially (using a single virtual CPU). In addition, it uses a mark-compact
collection method. This method moves older memory to the beginning of the
heap so that new memory allocations are made into a single continuous chunk
of memory at the end of the heap. This compacting of memory makes it faster to
allocate new chunks of memory to the heap.
The Parallel GC
The parallel garbage collector uses multiple threads to perform the
young genertion garbage collection. By default on a host with N CPUs,
the parallel garbage collector uses N garbage collector threads in the
collection. The number of garbage collector threads can be controlled
with command-line options:
-XX:ParallelGCThreads=<desired number>
On a host with a single CPU the default garbage collector is used even
if the parallel garbage collector has been requested. On a host with two
CPUs the parallel garbage collector generally performs as well as the
default garbage collector and a reduction in the young generation
garbage collector pause times can be expected on hosts with more than
two CPUs. The Parallel GC comes in two flavors.
The Parallel collector is also called a throughput collector. Since it can
use multilple CPUs to speed up application throughput. This collector
should be used when a lot of work need to be done and long pauses
are acceptable. For example, batch processing like printing reports or
bills or performing a large number of database queries.
Parallel Old GC(-XX:+UseParallelOldGC)
โ— Parallel Old GC was supported since JDK 5 update.
Compared to the parallel GC, the only difference is the GC
algorithm for the old generation. It goes through three
steps: mark โ€“ summary โ€“ compaction. The summary step
identifies the surviving objects separately for the areas that
the GC have previously performed, and thus different from
the sweep step of the mark-sweep-compact algorithm. It
goes through a little more complicated steps.
The Concurrent Mark Sweep (CMS) Collector
(-XX:+UseConcMarkSweepGC)
The Concurrent Mark Sweep (CMS) collector (also
referred to as the concurrent low pause collector) collects
the tenured generation. It attempts to minimize the pauses
due to garbage collection by doing most of the garbage
collection work concurrently with the application threads.
Normally the concurrent low pause collector does not copy
or compact the live objects. A garbage collection is done
without moving the live objects. If fragmentation becomes
a problem, allocate a larger heap.
The G1 Garbage Collector
The Garbage First or G1 garbage collector is available in Java 7 and is designed to be the
long term replacement for the CMS collector. The G1 collector is a parallel, concurrent,
and incrementally compacting low-pause garbage collector that has quite a different
layout from the other garbage collectors described previously.
In G1 garbage collector, one object is allocated to each grid, and then a GC is executed.
Then, once one area is full, the objects are allocated to another area, and then a GC is
executed. The steps where the data moves from the three spaces of the young generation
to the old generation cannot be found in this GC type. This type was created to replace
the CMS GC, which has causes a lot of issues and complaints in the long term.
The biggest advantage of the G1 GC is its performance. It is faster than any other GC
types that we have discussed so far. But in JDK 6, this is called an early access and can
be used only for a test. It is officially included in JDK 7.

More Related Content

What's hot (20)

PPTX
Graph traversals in Data Structures
Anandhasilambarasan D
ย 
PPTX
Awt, Swing, Layout managers
swapnac12
ย 
PPT
Deadlock Detection
Stuart Joy
ย 
PPTX
OOPS In JAVA.pptx
Sachin33417
ย 
PPTX
Presentation on-exception-handling
Nahian Ahmed
ย 
PPTX
Transaction Properties in database | ACID Properties
nomanbarki
ย 
PPTX
Doubly Linked List
Ninad Mankar
ย 
PPTX
Applets in java
Wani Zahoor
ย 
PPTX
Circular link list.ppt
Tirthika Bandi
ย 
PPTX
Exception Handling in object oriented programming using C++
Janki Shah
ย 
PPTX
Java string handling
Salman Khan
ย 
PPT
15. Transactions in DBMS
koolkampus
ย 
PPTX
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
ย 
PPTX
VB.NET:An introduction to Namespaces in .NET framework
Richa Handa
ย 
PPTX
classes and objects in C++
HalaiHansaika
ย 
PPTX
Linked list
akshat360
ย 
PPT
Asymptotic notation
Dr Shashikant Athawale
ย 
PPTX
linear probing
rajshreemuthiah
ย 
PPTX
Sorting
Ashim Lamichhane
ย 
PPTX
Transaction management DBMS
Megha Patel
ย 
Graph traversals in Data Structures
Anandhasilambarasan D
ย 
Awt, Swing, Layout managers
swapnac12
ย 
Deadlock Detection
Stuart Joy
ย 
OOPS In JAVA.pptx
Sachin33417
ย 
Presentation on-exception-handling
Nahian Ahmed
ย 
Transaction Properties in database | ACID Properties
nomanbarki
ย 
Doubly Linked List
Ninad Mankar
ย 
Applets in java
Wani Zahoor
ย 
Circular link list.ppt
Tirthika Bandi
ย 
Exception Handling in object oriented programming using C++
Janki Shah
ย 
Java string handling
Salman Khan
ย 
15. Transactions in DBMS
koolkampus
ย 
Java Notes by C. Sreedhar, GPREC
Sreedhar Chowdam
ย 
VB.NET:An introduction to Namespaces in .NET framework
Richa Handa
ย 
classes and objects in C++
HalaiHansaika
ย 
Linked list
akshat360
ย 
Asymptotic notation
Dr Shashikant Athawale
ย 
linear probing
rajshreemuthiah
ย 
Sorting
Ashim Lamichhane
ย 
Transaction management DBMS
Megha Patel
ย 

Viewers also liked (17)

PPTX
Introduction to jQuery
achinth
ย 
PPT
Mark and sweep algorithm(garbage collector)
Ashish Jha
ย 
PDF
Garbage Collection Pause Times - Angelika Langer
JAXLondon_Conference
ย 
PPTX
G1 Garbage Collector - Big Heaps and Low Pauses?
C2B2 Consulting
ย 
PPTX
G1 collector and tuning and Cassandra
Chris Lohfink
ย 
PDF
GC Tuning Confessions Of A Performance Engineer
Monica Beckwith
ย 
PPTX
Heap Management
Jenny Galino
ย 
PPTX
Garbage collection algorithms
achinth
ย 
PDF
How long can you afford to Stop The World?
Java Usergroup Berlin-Brandenburg
ย 
PDF
Understanding Java Garbage Collection
Azul Systems Inc.
ย 
PPTX
Java GC
Ray Cheng
ย 
PDF
Let's talk about Garbage Collection
Haim Yadid
ย 
PDF
Understanding Garbage Collection
Doug Hawkins
ย 
PPT
Basic Garbage Collection Techniques
An Khuong
ย 
PPT
Performance tuning jvm
Prem Kuppumani
ย 
PPTX
55 New Features in JDK 9
Simon Ritter
ย 
ODP
G1 Garbage Collector: Details and Tuning
Simone Bordet
ย 
Introduction to jQuery
achinth
ย 
Mark and sweep algorithm(garbage collector)
Ashish Jha
ย 
Garbage Collection Pause Times - Angelika Langer
JAXLondon_Conference
ย 
G1 Garbage Collector - Big Heaps and Low Pauses?
C2B2 Consulting
ย 
G1 collector and tuning and Cassandra
Chris Lohfink
ย 
GC Tuning Confessions Of A Performance Engineer
Monica Beckwith
ย 
Heap Management
Jenny Galino
ย 
Garbage collection algorithms
achinth
ย 
How long can you afford to Stop The World?
Java Usergroup Berlin-Brandenburg
ย 
Understanding Java Garbage Collection
Azul Systems Inc.
ย 
Java GC
Ray Cheng
ย 
Let's talk about Garbage Collection
Haim Yadid
ย 
Understanding Garbage Collection
Doug Hawkins
ย 
Basic Garbage Collection Techniques
An Khuong
ย 
Performance tuning jvm
Prem Kuppumani
ย 
55 New Features in JDK 9
Simon Ritter
ย 
G1 Garbage Collector: Details and Tuning
Simone Bordet
ย 
Ad

Similar to Garbage collection (20)

ODP
Garbage Collection in Hotspot JVM
jaganmohanreddyk
ย 
PPTX
Memory Management in the Java Virtual Machine(Garbage collection)
Prashanth Kumar
ย 
PDF
Java Garbage Collection - How it works
Mindfire Solutions
ย 
PDF
Garbage Collection in Java.pdf
SudhanshiBakre1
ย 
PDF
JVM Performance Tuning
Jeremy Leisy
ย 
PDF
JVM memory metrics and rules for detecting possible OOM caused crash
Atharva Bhingarkar
ย 
PDF
JVM memory metrics and rules for detecting likely OOM caused crash
Ajit Bhingarkar
ย 
DOC
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
sidg75
ย 
PDF
Performance Tuning - Understanding Garbage Collection
Haribabu Nandyal Padmanaban
ย 
PPTX
Garbage collection in C#,important topic
ksks28058
ย 
PDF
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Jelastic Multi-Cloud PaaS
ย 
PDF
A Novel Design of a Parallel Machine Learnt Generational Garbage Collector
cseij
ย 
PDF
A novel design of a parallel machine learnt
cseij
ย 
PPTX
An introduction to G1 collector for busy developers
Sanjoy Kumar Roy
ย 
PDF
Profiler Guided Java Performance Tuning
osa_ora
ย 
PPTX
JVM Magic
Baruch Sadogursky
ย 
PDF
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Jelastic Multi-Cloud PaaS
ย 
PDF
Memory Management in Go: Stack, Heap & Garbage Collector
Wednesday Solutions
ย 
PDF
A quick view about Java Virtual Machine
Joรฃo Santana
ย 
PDF
Java at Scale, Dallas JUG, October 2013
Azul Systems Inc.
ย 
Garbage Collection in Hotspot JVM
jaganmohanreddyk
ย 
Memory Management in the Java Virtual Machine(Garbage collection)
Prashanth Kumar
ย 
Java Garbage Collection - How it works
Mindfire Solutions
ย 
Garbage Collection in Java.pdf
SudhanshiBakre1
ย 
JVM Performance Tuning
Jeremy Leisy
ย 
JVM memory metrics and rules for detecting possible OOM caused crash
Atharva Bhingarkar
ย 
JVM memory metrics and rules for detecting likely OOM caused crash
Ajit Bhingarkar
ย 
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
sidg75
ย 
Performance Tuning - Understanding Garbage Collection
Haribabu Nandyal Padmanaban
ย 
Garbage collection in C#,important topic
ksks28058
ย 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Jelastic Multi-Cloud PaaS
ย 
A Novel Design of a Parallel Machine Learnt Generational Garbage Collector
cseij
ย 
A novel design of a parallel machine learnt
cseij
ย 
An introduction to G1 collector for busy developers
Sanjoy Kumar Roy
ย 
Profiler Guided Java Performance Tuning
osa_ora
ย 
JVM Magic
Baruch Sadogursky
ย 
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Jelastic Multi-Cloud PaaS
ย 
Memory Management in Go: Stack, Heap & Garbage Collector
Wednesday Solutions
ย 
A quick view about Java Virtual Machine
Joรฃo Santana
ย 
Java at Scale, Dallas JUG, October 2013
Azul Systems Inc.
ย 
Ad

Recently uploaded (20)

PDF
Malaysiaโ€™s e-Invoice System: A Complete Guide for Businesses
Matiyas Solutions
ย 
PPT
Brief History of Python by Learning Python in three hours
adanechb21
ย 
PPTX
TexSender Pro 8.9.1 Crack Full Version Download
cracked shares
ย 
PPTX
Farrell__10e_ch04_PowerPoint.pptx Programming Logic and Design slides
bashnahara11
ย 
PDF
Infrastructure planning and resilience - Keith Hastings.pptx.pdf
Safe Software
ย 
PPTX
ChessBase 18.02 Crack + Serial Key Free Download
cracked shares
ย 
PDF
Salesforce Pricing Update 2025: Impact, Strategy & Smart Cost Optimization wi...
GetOnCRM Solutions
ย 
PDF
AI Image Enhancer: Revolutionizing Visual Qualityโ€
docmasoom
ย 
PPTX
Cutting Optimization Pro 5.18.2 Crack With Free Download
cracked shares
ย 
PDF
Supabase Meetup: Build in a weekend, scale to millions
Carlo Gilmar Padilla Santana
ย 
PDF
AI Software Engineering based on Multi-view Modeling and Engineering Patterns
Hironori Washizaki
ย 
PDF
Virtual Threads in Java: A New Dimension of Scalability and Performance
Tier1 app
ย 
PDF
SAP GUI Installation Guide for macOS (iOS) | Connect to SAP Systems on Mac
SAP Vista, an A L T Z E N Company
ย 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
ย 
PDF
How Agentic AI Networks are Revolutionizing Collaborative AI Ecosystems in 2025
ronakdubey419
ย 
PPTX
Operations Profile SPDX_Update_20250711_Example_05_03.pptx
Shane Coughlan
ย 
PDF
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
ย 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
ย 
PPTX
Employee salary prediction using Machine learning Project template.ppt
bhanuk27082004
ย 
PDF
Odoo Customization Services by CandidRoot Solutions
CandidRoot Solutions Private Limited
ย 
Malaysiaโ€™s e-Invoice System: A Complete Guide for Businesses
Matiyas Solutions
ย 
Brief History of Python by Learning Python in three hours
adanechb21
ย 
TexSender Pro 8.9.1 Crack Full Version Download
cracked shares
ย 
Farrell__10e_ch04_PowerPoint.pptx Programming Logic and Design slides
bashnahara11
ย 
Infrastructure planning and resilience - Keith Hastings.pptx.pdf
Safe Software
ย 
ChessBase 18.02 Crack + Serial Key Free Download
cracked shares
ย 
Salesforce Pricing Update 2025: Impact, Strategy & Smart Cost Optimization wi...
GetOnCRM Solutions
ย 
AI Image Enhancer: Revolutionizing Visual Qualityโ€
docmasoom
ย 
Cutting Optimization Pro 5.18.2 Crack With Free Download
cracked shares
ย 
Supabase Meetup: Build in a weekend, scale to millions
Carlo Gilmar Padilla Santana
ย 
AI Software Engineering based on Multi-view Modeling and Engineering Patterns
Hironori Washizaki
ย 
Virtual Threads in Java: A New Dimension of Scalability and Performance
Tier1 app
ย 
SAP GUI Installation Guide for macOS (iOS) | Connect to SAP Systems on Mac
SAP Vista, an A L T Z E N Company
ย 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
ย 
How Agentic AI Networks are Revolutionizing Collaborative AI Ecosystems in 2025
ronakdubey419
ย 
Operations Profile SPDX_Update_20250711_Example_05_03.pptx
Shane Coughlan
ย 
Step-by-Step Guide to Install SAP HANA Studio | Complete Installation Tutoria...
SAP Vista, an A L T Z E N Company
ย 
Presentation about Database and Database Administrator
abhishekchauhan86963
ย 
Employee salary prediction using Machine learning Project template.ppt
bhanuk27082004
ย 
Odoo Customization Services by CandidRoot Solutions
CandidRoot Solutions Private Limited
ย 

Garbage collection

  • 1. GARBAGE COLLECTOR Automatic garbage collection is the process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects. An in use object, or a referenced object, means that some part of your program still maintains a pointer to that object. An unused object, or unreferenced object, is no longer referenced by any part of your program. So the memory used by an unreferenced object can be reclaimed. In a programming language like C, allocating and deallocating memory is a manual process. In Java, process of deallocating memory is handled automatically by the garbage collector.
  • 2. The basic process can be described as follows: โ— Step 1: Marking The first step in the process is called marking. This is where the garbage collector identifies which pieces of memory are in use and which are not. Referenced objects are shown in blue. Unreferenced objects are shown in gold. All objects are scanned in the marking phase to make this determination. This can be a very time consuming process if all objects in a system must be scanned.
  • 3. Step 2: Normal Deletion Normal deletion removes unreferenced objects leaving referenced objects and pointers to free space. The memory allocator holds references to blocks of free space where new object can be allocated.
  • 4. Step 2a: Deletion with Compacting To further improve performance, in addition to deleting unreferenced objects, you can also compact the remaining referenced objects. By moving referenced object together, this makes new memory allocation much easier and faster.
  • 5. Why Generational Garbage Collection? โ— As stated earlier, having to mark and compact all the objects in a JVM is inefficient. As more and more objects are allocated, the list of objects grows and grows leading to longer and longer garbage collection time. However, empirical analysis of applications has shown that most objects are short lived. JVM Generations โ— The information learned from the object allocation behavior can be used to enhance the performance of the JVM. Therefore, the heap is broken up into smaller parts or generations. The heap parts are: Young Generation, Old or Tenured Generation Permanent Generation โ— The Young Generation is where all new objects are allocated and aged. When the young generation fills up, this causes a minor garbage collection. Minor collections can be optimized assuming a high object mortality rate. A young generation full of dead objects is collected very quickly. Some surviving objects are aged and eventually move to the old generation.
  • 6. โ— Stop the World Event - All minor garbage collections are "Stop the World" events. This means that all application threads are stopped until the operation completes. Minor garbage collections are always Stop the World events. โ— The Old Generation is used to store long surviving objects. Typically, a threshold is set for young generation object and when that age is met, the object gets moved to the old generation. Eventually the old generation needs to be collected. This event is called a major garbage collection. โ— Major garbage collection are also Stop the World events. Often a major collection is much slower because it involves all live objects. So for Responsive applications, major garbage collections should be minimized. Also note, that the length of the Stop the World event for a major garbage collection is affected by the kind of garbage collector that is used for the old generation space. โ— The Permanent generation contains metadata required by the JVM to describe the classes and methods used in the application. The permanent generation is populated by the JVM at runtime based on classes in use by the application. In addition, Java SE library classes and methods may be stored here. โ— Classes may get collected (unloaded) if the JVM finds they are no longer needed and space may be needed for other classes. The permanent generation is included in a full garbage collection.
  • 7. The pictures that follow walks through the object allocation and aging process in the JVM: First, any new objects are allocated to the eden space. Both survivor spaces start out empty.
  • 8. When the eden space fills up, a minor garbage collection is triggered.
  • 9. โ— Referenced objects are moved to the first survivor space. Unreferenced objects are deleted when the eden space is cleared.
  • 10. โ— At the next minor GC, the same thing happens for the eden space. Unreferenced objects are deleted and referenced objects are moved to a survivor space. However, in this case, they are moved to the second survivor space (S1). In addition, objects from the last minor GC on the first survivor space (S0) have their age incremented and get moved to S1. Once all surviving objects have been moved to S1, both S0 and eden are cleared. Notice we now have differently aged object in the survivor space.
  • 11. โ— At the next minor GC, the same process repeats. However this time the survivor spaces switch. Referenced objects are moved to S0. Surviving objects are aged. Eden and S1 are cleared.
  • 12. โ— This slide demonstrates promotion. After a minor GC, when aged objects reach a certain age threshold (8 in this example) they are promoted from young generation to old generation.
  • 13. โ— As minor GCs continue to occure objects will continue to be promoted to the old generation space.
  • 14. โ— So that pretty much covers the entire process with the young generation. Eventually, a major GC will be performed on the old generation which cleans up and compacts that space.
  • 16. Common Heap Related Switches There are many different command line switches that can be used with Java. Switch Description -Xms Sets the initial heap size for when the JVM starts. -Xmx Sets the maximum heap size. -Xmn Sets the size of the Young Generation. -XX:PermSize Sets the starting size of the Permanent Generation. -XX:MaxPermSize Sets the maximum size of the Permanent Generation The Serial GC The serial collector is the default for client style machines in Java SE 5 and 6. With the serial collector, both minor and major garbage collections are done serially (using a single virtual CPU). In addition, it uses a mark-compact collection method. This method moves older memory to the beginning of the heap so that new memory allocations are made into a single continuous chunk of memory at the end of the heap. This compacting of memory makes it faster to allocate new chunks of memory to the heap.
  • 17. The Parallel GC The parallel garbage collector uses multiple threads to perform the young genertion garbage collection. By default on a host with N CPUs, the parallel garbage collector uses N garbage collector threads in the collection. The number of garbage collector threads can be controlled with command-line options: -XX:ParallelGCThreads=<desired number> On a host with a single CPU the default garbage collector is used even if the parallel garbage collector has been requested. On a host with two CPUs the parallel garbage collector generally performs as well as the default garbage collector and a reduction in the young generation garbage collector pause times can be expected on hosts with more than two CPUs. The Parallel GC comes in two flavors. The Parallel collector is also called a throughput collector. Since it can use multilple CPUs to speed up application throughput. This collector should be used when a lot of work need to be done and long pauses are acceptable. For example, batch processing like printing reports or bills or performing a large number of database queries.
  • 18. Parallel Old GC(-XX:+UseParallelOldGC) โ— Parallel Old GC was supported since JDK 5 update. Compared to the parallel GC, the only difference is the GC algorithm for the old generation. It goes through three steps: mark โ€“ summary โ€“ compaction. The summary step identifies the surviving objects separately for the areas that the GC have previously performed, and thus different from the sweep step of the mark-sweep-compact algorithm. It goes through a little more complicated steps.
  • 19. The Concurrent Mark Sweep (CMS) Collector (-XX:+UseConcMarkSweepGC) The Concurrent Mark Sweep (CMS) collector (also referred to as the concurrent low pause collector) collects the tenured generation. It attempts to minimize the pauses due to garbage collection by doing most of the garbage collection work concurrently with the application threads. Normally the concurrent low pause collector does not copy or compact the live objects. A garbage collection is done without moving the live objects. If fragmentation becomes a problem, allocate a larger heap.
  • 20. The G1 Garbage Collector The Garbage First or G1 garbage collector is available in Java 7 and is designed to be the long term replacement for the CMS collector. The G1 collector is a parallel, concurrent, and incrementally compacting low-pause garbage collector that has quite a different layout from the other garbage collectors described previously. In G1 garbage collector, one object is allocated to each grid, and then a GC is executed. Then, once one area is full, the objects are allocated to another area, and then a GC is executed. The steps where the data moves from the three spaces of the young generation to the old generation cannot be found in this GC type. This type was created to replace the CMS GC, which has causes a lot of issues and complaints in the long term. The biggest advantage of the G1 GC is its performance. It is faster than any other GC types that we have discussed so far. But in JDK 6, this is called an early access and can be used only for a test. It is officially included in JDK 7.