SlideShare a Scribd company logo
12
Most read
14
Most read
20
Most read
Java Garbage Collection
Presenter: Rupal Chatterjee, Mindfire Solutions
Date: 27/09/2013
Java Memory Management

Presenter: Rupal Chatterjee, Mindfire Solutions
Java Memory Management (Contd...)
The first tier consists of Heap
Stores all created objects in runtime.
PermGen / Method Area
- The segment where the actual compiled Java byte codes resides when loaded.
- Static members (variables or methods) also reside in this segment.
- PermGen is also considered as a part of Heap.
Thread 1..N / Stack
Stores local variables and Reference variables(variables that hold the address of an
object in the heap)

Presenter: Rupal Chatterjee, Mindfire Solutions
Java Memory Management (Contd...)
Key Notes 1. Classes (loaded by the class-loaders) go tp Permanent Generation area.
2. All the static member variables are kept on the Permanent Generation area.
3. All variables except the static ones are kept in Stack.
4. Objects created run-time are stored in heap.
5. There is only one copy of each method per class, be the method static or non-static.
That copy is put in the Permanent Generation area.

Presenter: Rupal Chatterjee, Mindfire Solutions
Java Memory Management (Contd...)
Key Notes (Contd...) 6. For non-static and static methods, all the parameters and local variables go onto the
stack.
7. The return value of a method get stored in stack.
8. Local variables reside in stack.
– Memory allocated at method invocation time.
– Memory deallocated when method returns.
9. Objects reside in heap.
– Memory is allocated with new keyword.
– But never explicitly deallocated.
10. Java uses a automatic mechanism to free heap memory.

Presenter: Rupal Chatterjee, Mindfire Solutions
Java Memory Management (Contd...)

Source: http://blog.pointsoftware.ch

Presenter: Rupal Chatterjee, Mindfire Solutions
Garbage Collection
Key Notes 1. It is a mechanism provided by Java Virtual Machine to reclaim heap space from
objects which are eligible for Garbage collection.
2. Garbage collection relieves java programmer from memory management which is
essential part of C++ programming and gives more time to focus on business logic.
3. Garbage Collection in Java is carried by a thread called Garbage Collector.
4. Before removing an object from memory, Garbage collection thread invokes finalize()
method of that object and gives an opportunity to perform any sort of custom cleanup
required.

Presenter: Rupal Chatterjee, Mindfire Solutions
Garbage Collection (Contd...)
Key Notes (Contd...) 5. Programmer can not force Garbage collection in Java; it will only trigger if JVM thinks
it needs a garbage collection based on Java heap size.
6. There are methods like System.gc() and Runtime.gc() which is used to send request
of Garbage collection to JVM but it’s not guaranteed that garbage collection will be
triggered right away.
7. If there is no memory space present for creating new objects in Heap, Java Virtual
Machine throws OutOfMemoryError or java.lang.OutOfMemoryError.

Presenter: Rupal Chatterjee, Mindfire Solutions
Garbage Collection (Contd...)
When an Object becomes Eligible for Garbage Collection
If its not reachable from any references, in other words you can say that an object
becomes eligible for garbage collection if its all references are null.
Cyclic dependencies are not counted as reference so if Object A has reference of
Object B and Object B has reference of Object A and they don't have any other live
reference then both Objects A and B will be eligible for Garbage collection.
Generally an object becomes eligible for garbage collection in Java on following cases:
1) All references of that object explicitly set to null e.g. object = null
2) Object is created inside a block and reference goes out of scope once control exit that
block.
3) Parent object set to null, if an object holds reference of another object and parent
object's reference set to null, child objects automatically becomes eligible for garbage
collection.

Presenter: Rupal Chatterjee, Mindfire Solutions
Garbage Collection (Contd...)
How it works?
Java objects are created in Heap and Heap is divided into two parts or generations for
sake of garbage collection in Java, these are called as Young Generation and Tenured
or Old Generation.

Presenter: Rupal Chatterjee, Mindfire Solutions
Garbage Collection (Contd...)
How it works? (Contd...)
Young Generation is further divided into three parts.
- Eden space,
- From Space (Survivor 1)
- To Space (Survivor 2)
When an object first created,
1) It gets into Young Generation inside Eden space.
2) After subsequent Minor Garbage Collection, if object survives it gets moved to
From Space / Survivor 1.
3) Then to To Space / Survivor 2.
4) Then eventually object moved to Old or Tenured Generation.

Presenter: Rupal Chatterjee, Mindfire Solutions
Garbage Collection (Contd...)
How it works? (Contd...)
Young Generation is where all new objects are allocated and aged. When the young
generation fills up, this causes a minor garbage collection. 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.
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.
(extract from Oracle site)

Presenter: Rupal Chatterjee, Mindfire Solutions
Type of Garbage Collectors
The Serial GC
1. The serial collector is the default GC in Java SE 5 and 6.
2. Here both minor and major garbage collections are done using a single Thread.
3. It uses a mark-compact collection method.
4. Compacting of memory makes it faster to allocate new chunks of memory to the heap.
5. The Serial GC is the choice for most applications that do not have low pause time
requirements.
6. To enable the Serial Collector use: -XX:+UseSerialGC
Here is a sample command line for starting a sample JAR:
java -XX:+UseSerialGC -jar GcTest.jar
Presenter: Rupal Chatterjee, Mindfire Solutions
Type of Garbage Collectors (Contd...)
The Parallel GC
1. The parallel GC uses multiple threads to perform minor garbage collections.
2. By default on a host with N CPUs, the parallel GC uses N GC threads in the
collection.
3. The number of GC threads can be controlled with command-line options:
-XX:ParallelGCThreads=<desired number>.
4. On a host with a single CPU the default GC is used even if the parallel GC has been
requested.
5. On a host with two CPUs the parallel GC generally performs as well as the default
GC.

Presenter: Rupal Chatterjee, Mindfire Solutions
Type of Garbage Collectors (Contd...)
The Parallel GC (Contd...)
6.. Reduction in the young generation GC pause times can be expected on hosts with
more than two CPUs.
7. There are two ways to enable Parallel GC,
-XX:+UseParallelGC, With this command line option you get a multi-thread young
GC with a single-threaded old GC.
-XX:+UseParallelOldGC, With this option, you get both a multi-threaded young GC
and multi-threaded old GC.

Presenter: Rupal Chatterjee, Mindfire Solutions
Type of Garbage Collectors (Contd...)
The Concurrent Mark Sweep (CMS) Collector
1. It collects the old / tenured generation.
2. Here garbage collection is done concurrently with the application thread. Hence it
reduces the pause time.
3. As it works with live object, compacting is not done here.
4. CMS collectors are used for applications which require low pause time.
5. To enable the CMS Collector use: -XX:+UseConcMarkSweepGC
6. To set the number of threads use: -XX:ParallelCMSThreads=<n>
Here is a sample command line for starting a sample JAR:
java -XX:+UseConcMarkSweepGC -XX:ParallelCMSThreads=2 -jar GcTest.jar

Presenter: Rupal Chatterjee, Mindfire Solutions
Type of Garbage Collectors (Contd...)
The G1 Garbage Collector
1. The Garbage First or G1 garbage collector is available in Java 7.
2. It is designed to be the long term replacement for the CMS collector.
3. The G1 collector is a parallel, concurrent, and compacting low-pause garbage
collector.
4. To enable the G1 Collector use: -XX:+UseG1GC
Here is a sample command line for starting a sample JAR:
java -XX:+UseG1GC -jar GcTest.jar

Presenter: Rupal Chatterjee, Mindfire Solutions
Full GC And Concurrent GC
1. Concurrent GC in java runs concurrently with the application threads.
2. The goal is to complete the collection of Tenured Generation before it becomes full.
3. If the Concurrent GC fails to finish before the Tenured Generation fill up. Then?
4. The application will be paused and the collection is completed with all the application
threads stopped.
5. Such collections with the application stopped are referred as Full GC.
6. Full GC affects performance of Java applications.

Presenter: Rupal Chatterjee, Mindfire Solutions
Summary on Garbage collection in Java
1. Java Heap is divided into three generation for sake of garbage collection. These are
Young Generation, Tenured or Old Generation and PermGen.
2. New objects are created in Young Generation and subsequently moved to Old
Generation.
3. Minor GC is used to move object from Eden space to Survivor 1 and Survivor 2
space and then to Tenured Generation.
4. Whenever Major GC occurs application threads stops during that period, which will
reduce application’s performance.
5. JVM command line options –Xmx and -Xms is used to setup min and max size for
Java Heap. Ideal ratio of this parameter is either 1:1 or 1:1.5.
6. There is no manual way of doing garbage collection in Java.

Presenter: Rupal Chatterjee, Mindfire Solutions
Question and
Answer

Presenter: Rupal Chatterjee, Mindfire Solutions
Thank you

Presenter: Rupal Chatterjee, Mindfire Solutions

More Related Content

PDF
Introduction to Customer Journey Mapping
PPTX
Packages in java
PPT
Simple Linier Regression
PPTX
Garbage collection
PPT
Java Networking
PPTX
oops concept in java | object oriented programming in java
PPSX
Heuristic evaluation principles
PPTX
Slowly changing dimension
Introduction to Customer Journey Mapping
Packages in java
Simple Linier Regression
Garbage collection
Java Networking
oops concept in java | object oriented programming in java
Heuristic evaluation principles
Slowly changing dimension

What's hot (20)

PPT
Final keyword in java
PPTX
History Of JAVA
PDF
Collections in Java Notes
PPS
Wrapper class
PPTX
Method overloading
ODP
Garbage collection
PDF
Polymorphism In Java
PPTX
Exception Handling in Java
PPTX
PPTX
Super Keyword in Java.pptx
PPTX
Classes objects in java
PPS
Java Exception handling
PDF
Java threads
PPT
Java Notes
PPTX
WHAT IS ABSTRACTION IN JAVA
PPTX
Event handling
PPTX
Constructor in java
PPTX
Java exception handling
Final keyword in java
History Of JAVA
Collections in Java Notes
Wrapper class
Method overloading
Garbage collection
Polymorphism In Java
Exception Handling in Java
Super Keyword in Java.pptx
Classes objects in java
Java Exception handling
Java threads
Java Notes
WHAT IS ABSTRACTION IN JAVA
Event handling
Constructor in java
Java exception handling
Ad

Viewers also liked (20)

PDF
Understanding Java Garbage Collection
PPT
An Introduction to JVM Internals and Garbage Collection in Java
PPT
Garbage collection in JVM
PDF
Understanding Java Garbage Collection - And What You Can Do About It
PPTX
Java GC
PDF
Understanding Garbage Collection
ODP
Java Garbage Collection, Monitoring, and Tuning
PDF
Java Garbage Collection
PPS
15 ooad uml-20
PPS
Oops recap
PPS
11 ds and algorithm session_16
PPS
Dacj 2-2 c
PPS
Vb.net session 09
PPS
09 iec t1_s1_oo_ps_session_13
PDF
OOP Java
PPS
Jdbc session01
PPS
Rdbms xp 01
PPTX
Garbage collection algorithms
PPS
14 ooad uml-19
Understanding Java Garbage Collection
An Introduction to JVM Internals and Garbage Collection in Java
Garbage collection in JVM
Understanding Java Garbage Collection - And What You Can Do About It
Java GC
Understanding Garbage Collection
Java Garbage Collection, Monitoring, and Tuning
Java Garbage Collection
15 ooad uml-20
Oops recap
11 ds and algorithm session_16
Dacj 2-2 c
Vb.net session 09
09 iec t1_s1_oo_ps_session_13
OOP Java
Jdbc session01
Rdbms xp 01
Garbage collection algorithms
14 ooad uml-19
Ad

Similar to Java Garbage Collection - How it works (20)

PDF
Garbage Collection in Java.pdf
PDF
Profiler Guided Java Performance Tuning
PPTX
Javasession10
PDF
JVM Performance Tuning
PDF
.NET Core, ASP.NET Core Course, Session 4
ODP
Garbage Collection in Hotspot JVM
PPT
Jvm performance tuning
PPT
Java programing considering performance
PPTX
Memory Management in the Java Virtual Machine(Garbage collection)
PDF
Memory Leaks in Android Applications
PDF
Let's talk about Garbage Collection
DOC
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
PDF
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
PPTX
Learn Microsoft Asp.Net Garbage Collection
DOCX
Garbage collector complete information
PPT
Efficient Memory and Thread Management in Highly Parallel Java Applications
PPTX
Garbage collection in C#,important topic
PDF
Why using finalizers is a bad idea
PDF
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
PDF
A novel design of a parallel machine learnt
Garbage Collection in Java.pdf
Profiler Guided Java Performance Tuning
Javasession10
JVM Performance Tuning
.NET Core, ASP.NET Core Course, Session 4
Garbage Collection in Hotspot JVM
Jvm performance tuning
Java programing considering performance
Memory Management in the Java Virtual Machine(Garbage collection)
Memory Leaks in Android Applications
Let's talk about Garbage Collection
Garbage Collection, Tuning And Monitoring JVM In EBS 11i And R12
Performance Tuning - Memory leaks, Thread deadlocks, JDK tools
Learn Microsoft Asp.Net Garbage Collection
Garbage collector complete information
Efficient Memory and Thread Management in Highly Parallel Java Applications
Garbage collection in C#,important topic
Why using finalizers is a bad idea
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
A novel design of a parallel machine learnt

More from Mindfire Solutions (20)

PDF
Physician Search and Review
PDF
diet management app
PDF
Business Technology Solution
PDF
Remote Health Monitoring
PDF
Influencer Marketing Solution
PPT
High Availability of Azure Applications
PPTX
IOT Hands On
PPTX
Glimpse of Loops Vs Set
ODP
Oracle Sql Developer-Getting Started
PPT
Adaptive Layout In iOS 8
PPT
Introduction to Auto-layout : iOS/Mac
PPT
LINQPad - utility Tool
PPT
Get started with watch kit development
PPTX
Swift vs Objective-C
ODP
Material Design in Android
ODP
Introduction to OData
PPT
Ext js Part 2- MVC
PPT
ExtJs Basic Part-1
PPT
Spring Security Introduction
Physician Search and Review
diet management app
Business Technology Solution
Remote Health Monitoring
Influencer Marketing Solution
High Availability of Azure Applications
IOT Hands On
Glimpse of Loops Vs Set
Oracle Sql Developer-Getting Started
Adaptive Layout In iOS 8
Introduction to Auto-layout : iOS/Mac
LINQPad - utility Tool
Get started with watch kit development
Swift vs Objective-C
Material Design in Android
Introduction to OData
Ext js Part 2- MVC
ExtJs Basic Part-1
Spring Security Introduction

Recently uploaded (20)

PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Electronic commerce courselecture one. Pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Modernizing your data center with Dell and AMD
PPTX
Big Data Technologies - Introduction.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
cuic standard and advanced reporting.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
madgavkar20181017ppt McKinsey Presentation.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Electronic commerce courselecture one. Pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Modernizing your data center with Dell and AMD
Big Data Technologies - Introduction.pptx
Chapter 3 Spatial Domain Image Processing.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
“AI and Expert System Decision Support & Business Intelligence Systems”
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
NewMind AI Monthly Chronicles - July 2025
Advanced methodologies resolving dimensionality complications for autism neur...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Spectroscopy.pptx food analysis technology
Spectral efficient network and resource selection model in 5G networks
cuic standard and advanced reporting.pdf
NewMind AI Weekly Chronicles - August'25 Week I
Dropbox Q2 2025 Financial Results & Investor Presentation

Java Garbage Collection - How it works

  • 1. Java Garbage Collection Presenter: Rupal Chatterjee, Mindfire Solutions Date: 27/09/2013
  • 2. Java Memory Management Presenter: Rupal Chatterjee, Mindfire Solutions
  • 3. Java Memory Management (Contd...) The first tier consists of Heap Stores all created objects in runtime. PermGen / Method Area - The segment where the actual compiled Java byte codes resides when loaded. - Static members (variables or methods) also reside in this segment. - PermGen is also considered as a part of Heap. Thread 1..N / Stack Stores local variables and Reference variables(variables that hold the address of an object in the heap) Presenter: Rupal Chatterjee, Mindfire Solutions
  • 4. Java Memory Management (Contd...) Key Notes 1. Classes (loaded by the class-loaders) go tp Permanent Generation area. 2. All the static member variables are kept on the Permanent Generation area. 3. All variables except the static ones are kept in Stack. 4. Objects created run-time are stored in heap. 5. There is only one copy of each method per class, be the method static or non-static. That copy is put in the Permanent Generation area. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 5. Java Memory Management (Contd...) Key Notes (Contd...) 6. For non-static and static methods, all the parameters and local variables go onto the stack. 7. The return value of a method get stored in stack. 8. Local variables reside in stack. – Memory allocated at method invocation time. – Memory deallocated when method returns. 9. Objects reside in heap. – Memory is allocated with new keyword. – But never explicitly deallocated. 10. Java uses a automatic mechanism to free heap memory. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 6. Java Memory Management (Contd...) Source: http://blog.pointsoftware.ch Presenter: Rupal Chatterjee, Mindfire Solutions
  • 7. Garbage Collection Key Notes 1. It is a mechanism provided by Java Virtual Machine to reclaim heap space from objects which are eligible for Garbage collection. 2. Garbage collection relieves java programmer from memory management which is essential part of C++ programming and gives more time to focus on business logic. 3. Garbage Collection in Java is carried by a thread called Garbage Collector. 4. Before removing an object from memory, Garbage collection thread invokes finalize() method of that object and gives an opportunity to perform any sort of custom cleanup required. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 8. Garbage Collection (Contd...) Key Notes (Contd...) 5. Programmer can not force Garbage collection in Java; it will only trigger if JVM thinks it needs a garbage collection based on Java heap size. 6. There are methods like System.gc() and Runtime.gc() which is used to send request of Garbage collection to JVM but it’s not guaranteed that garbage collection will be triggered right away. 7. If there is no memory space present for creating new objects in Heap, Java Virtual Machine throws OutOfMemoryError or java.lang.OutOfMemoryError. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 9. Garbage Collection (Contd...) When an Object becomes Eligible for Garbage Collection If its not reachable from any references, in other words you can say that an object becomes eligible for garbage collection if its all references are null. Cyclic dependencies are not counted as reference so if Object A has reference of Object B and Object B has reference of Object A and they don't have any other live reference then both Objects A and B will be eligible for Garbage collection. Generally an object becomes eligible for garbage collection in Java on following cases: 1) All references of that object explicitly set to null e.g. object = null 2) Object is created inside a block and reference goes out of scope once control exit that block. 3) Parent object set to null, if an object holds reference of another object and parent object's reference set to null, child objects automatically becomes eligible for garbage collection. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 10. Garbage Collection (Contd...) How it works? Java objects are created in Heap and Heap is divided into two parts or generations for sake of garbage collection in Java, these are called as Young Generation and Tenured or Old Generation. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 11. Garbage Collection (Contd...) How it works? (Contd...) Young Generation is further divided into three parts. - Eden space, - From Space (Survivor 1) - To Space (Survivor 2) When an object first created, 1) It gets into Young Generation inside Eden space. 2) After subsequent Minor Garbage Collection, if object survives it gets moved to From Space / Survivor 1. 3) Then to To Space / Survivor 2. 4) Then eventually object moved to Old or Tenured Generation. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 12. Garbage Collection (Contd...) How it works? (Contd...) Young Generation is where all new objects are allocated and aged. When the young generation fills up, this causes a minor garbage collection. 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. 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. (extract from Oracle site) Presenter: Rupal Chatterjee, Mindfire Solutions
  • 13. Type of Garbage Collectors The Serial GC 1. The serial collector is the default GC in Java SE 5 and 6. 2. Here both minor and major garbage collections are done using a single Thread. 3. It uses a mark-compact collection method. 4. Compacting of memory makes it faster to allocate new chunks of memory to the heap. 5. The Serial GC is the choice for most applications that do not have low pause time requirements. 6. To enable the Serial Collector use: -XX:+UseSerialGC Here is a sample command line for starting a sample JAR: java -XX:+UseSerialGC -jar GcTest.jar Presenter: Rupal Chatterjee, Mindfire Solutions
  • 14. Type of Garbage Collectors (Contd...) The Parallel GC 1. The parallel GC uses multiple threads to perform minor garbage collections. 2. By default on a host with N CPUs, the parallel GC uses N GC threads in the collection. 3. The number of GC threads can be controlled with command-line options: -XX:ParallelGCThreads=<desired number>. 4. On a host with a single CPU the default GC is used even if the parallel GC has been requested. 5. On a host with two CPUs the parallel GC generally performs as well as the default GC. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 15. Type of Garbage Collectors (Contd...) The Parallel GC (Contd...) 6.. Reduction in the young generation GC pause times can be expected on hosts with more than two CPUs. 7. There are two ways to enable Parallel GC, -XX:+UseParallelGC, With this command line option you get a multi-thread young GC with a single-threaded old GC. -XX:+UseParallelOldGC, With this option, you get both a multi-threaded young GC and multi-threaded old GC. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 16. Type of Garbage Collectors (Contd...) The Concurrent Mark Sweep (CMS) Collector 1. It collects the old / tenured generation. 2. Here garbage collection is done concurrently with the application thread. Hence it reduces the pause time. 3. As it works with live object, compacting is not done here. 4. CMS collectors are used for applications which require low pause time. 5. To enable the CMS Collector use: -XX:+UseConcMarkSweepGC 6. To set the number of threads use: -XX:ParallelCMSThreads=<n> Here is a sample command line for starting a sample JAR: java -XX:+UseConcMarkSweepGC -XX:ParallelCMSThreads=2 -jar GcTest.jar Presenter: Rupal Chatterjee, Mindfire Solutions
  • 17. Type of Garbage Collectors (Contd...) The G1 Garbage Collector 1. The Garbage First or G1 garbage collector is available in Java 7. 2. It is designed to be the long term replacement for the CMS collector. 3. The G1 collector is a parallel, concurrent, and compacting low-pause garbage collector. 4. To enable the G1 Collector use: -XX:+UseG1GC Here is a sample command line for starting a sample JAR: java -XX:+UseG1GC -jar GcTest.jar Presenter: Rupal Chatterjee, Mindfire Solutions
  • 18. Full GC And Concurrent GC 1. Concurrent GC in java runs concurrently with the application threads. 2. The goal is to complete the collection of Tenured Generation before it becomes full. 3. If the Concurrent GC fails to finish before the Tenured Generation fill up. Then? 4. The application will be paused and the collection is completed with all the application threads stopped. 5. Such collections with the application stopped are referred as Full GC. 6. Full GC affects performance of Java applications. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 19. Summary on Garbage collection in Java 1. Java Heap is divided into three generation for sake of garbage collection. These are Young Generation, Tenured or Old Generation and PermGen. 2. New objects are created in Young Generation and subsequently moved to Old Generation. 3. Minor GC is used to move object from Eden space to Survivor 1 and Survivor 2 space and then to Tenured Generation. 4. Whenever Major GC occurs application threads stops during that period, which will reduce application’s performance. 5. JVM command line options –Xmx and -Xms is used to setup min and max size for Java Heap. Ideal ratio of this parameter is either 1:1 or 1:1.5. 6. There is no manual way of doing garbage collection in Java. Presenter: Rupal Chatterjee, Mindfire Solutions
  • 20. Question and Answer Presenter: Rupal Chatterjee, Mindfire Solutions
  • 21. Thank you Presenter: Rupal Chatterjee, Mindfire Solutions