SlideShare a Scribd company logo
Java GC Study Garbage Collection Dhanu Gupta
Java GC Java objects are eligible for garbage collection (GC), which frees their memory and possibly associated resources, when they are no longer reachable Two stages of GC for an object finalization - runs finalize method on the object reclamation - reclaims memory used by the object
GC Process Basic steps object is determined to be unreachable if object has a finalize method object is added to a finalization queue at some point it’s finalize method is invoked so the object can free associated resources object memory is reclaimed Issues with finalize methods makes every GC pass do more work if a finalize method runs for a long time, it can delay execution of finalize methods of other objects may create new strong references to objects that had none,preventing their GC run in a nondeterministic order no guarantee they will be called; app. may exit first
Generational GC All of the GC algorithms used by Java are variations on the concept of generational GC •  Generational GC assumes that the most recently created objects are the ones that are most likely to become unreachable soon for example, objects created in a method and only referenced by local variables that go out of scope when the method exits the longer an object remains reachable,the less likely it is to be eligible for GC soon (or ever) Objects are divided into “generations” or “spaces” Java categories these with the names “ young”, “tenured” and “perm” objects can move from one space to another during a GC
Object Spaces Hold objects of similar ages or generations “ young” spaces hold recently created objects and can be GC’ed in a “minor” or “major” collection “ tenured” space hold objects that have survived some number of minor collections and can be GC’ed only in a major collection “ perm” space hold objects needed by the JVM, such as Class & Method objects, their byte code, and interned Strings GC of this space results in classes being “unloaded” Size of each space determined by current heap size(which can change during runtime) and several tuning options
Young Spaces Eden space holds objects created after the last GC,except those that belong in the perm space during a minor collection, these objects are either GC’ed or moved to a survivor space Survivor spaces these spaces hold young objects that have survived at least one GC during a minor collection, these objects are either GC’ed or moved to the other survivor space Minor collections tend to be fast compared to major collections because only a subset of the objects need to be examined typically occur much more frequently than major collections
When Does GC Occurs? Impacted by heap size “ If a heap size is small, collection will be fast but the heap will fill up more quickly,thus requiring more frequent collections.” “ Conversely, a large heap will take longer to fill up and thus collections will be less frequent,but they take longer.” Minor collections occur when a young space approaches being full Major collections occur when the tenured space approaches being full
Tools to see Heap Jconsole Memory Analyzer
Thanks Next I will shed More light on GC Properties.

More Related Content

ODP
Java GC, Off-heap workshop
PDF
淺談 Java GC 原理、調教和 新發展
PDF
淺談JavaFX 遊戲程式
PDF
[BGOUG] Java GC - Friend or Foe
PDF
Java gc
PDF
Java GC - Pause tuning
PPTX
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
PPTX
Java concurrency
Java GC, Off-heap workshop
淺談 Java GC 原理、調教和 新發展
淺談JavaFX 遊戲程式
[BGOUG] Java GC - Friend or Foe
Java gc
Java GC - Pause tuning
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Java concurrency

Viewers also liked (20)

PDF
Java Memory Model
PDF
Java Memory Model
PPTX
Николай Папирный Тема: "Java memory model для простых смертных"
ODP
Java Memory Consistency Model - concepts and context
PPTX
Java gc and JVM optimization
PDF
What you need to know about GC
ODP
Java memory model
PPTX
The Java Memory Model
PDF
How long can you afford to Stop The World?
PDF
JVM及其调优
PPTX
Tuning Java GC to resolve performance issues
PPTX
The Java memory model made easy
PDF
GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
PPTX
Java GC
PDF
Let's Learn to Talk to GC Logs in Java 9
PDF
Let's talk about Garbage Collection
PDF
Introduction of Java GC Tuning and Java Java Mission Control
PDF
Threads and Java Memory Model Explained
PDF
Java 9: The (G1) GC Awakens!
PDF
Java GC Tuning
Java Memory Model
Java Memory Model
Николай Папирный Тема: "Java memory model для простых смертных"
Java Memory Consistency Model - concepts and context
Java gc and JVM optimization
What you need to know about GC
Java memory model
The Java Memory Model
How long can you afford to Stop The World?
JVM及其调优
Tuning Java GC to resolve performance issues
The Java memory model made easy
GC Tuning in the HotSpot Java VM - a FISL 10 Presentation
Java GC
Let's Learn to Talk to GC Logs in Java 9
Let's talk about Garbage Collection
Introduction of Java GC Tuning and Java Java Mission Control
Threads and Java Memory Model Explained
Java 9: The (G1) GC Awakens!
Java GC Tuning
Ad

Similar to Java Garbage Collection(GC)- Study (20)

PDF
Java Garbage Collection
PDF
Java Garbage Collector and The Memory Model
PPT
An Introduction to JVM Internals and Garbage Collection in Java
ODP
Garbage Collection in Hotspot JVM
ODP
Garbage collection
PPTX
Garbage collection in java
PPTX
Java garbage collection & GC friendly coding
PDF
Performance Tuning - Understanding Garbage Collection
PPTX
Garbage collector (gc)
ODP
Quick introduction to Java Garbage Collector (JVM GC)
ODP
Java Garbage Collection, Monitoring, and Tuning
PDF
Low latency Java apps
PPTX
Garbage collection algorithms
PPTX
Garbage collection
DOCX
Garbage collector complete information
PPTX
Garbage collection Overview
PPT
Garbage collection in JVM
PDF
Java at Scale, Dallas JUG, October 2013
PPTX
Intro to Garbage Collection
PPTX
Java Garbage Collection
Java Garbage Collection
Java Garbage Collector and The Memory Model
An Introduction to JVM Internals and Garbage Collection in Java
Garbage Collection in Hotspot JVM
Garbage collection
Garbage collection in java
Java garbage collection & GC friendly coding
Performance Tuning - Understanding Garbage Collection
Garbage collector (gc)
Quick introduction to Java Garbage Collector (JVM GC)
Java Garbage Collection, Monitoring, and Tuning
Low latency Java apps
Garbage collection algorithms
Garbage collection
Garbage collector complete information
Garbage collection Overview
Garbage collection in JVM
Java at Scale, Dallas JUG, October 2013
Intro to Garbage Collection
Java Garbage Collection
Ad

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
Teaching material agriculture food technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Cloud computing and distributed systems.
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Encapsulation theory and applications.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Building Integrated photovoltaic BIPV_UPV.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Empathic Computing: Creating Shared Understanding
Digital-Transformation-Roadmap-for-Companies.pptx
NewMind AI Weekly Chronicles - August'25 Week I
Diabetes mellitus diagnosis method based random forest with bat algorithm
Teaching material agriculture food technology
Spectral efficient network and resource selection model in 5G networks
Unlocking AI with Model Context Protocol (MCP)
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Machine learning based COVID-19 study performance prediction
Cloud computing and distributed systems.
Dropbox Q2 2025 Financial Results & Investor Presentation
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
The AUB Centre for AI in Media Proposal.docx
Encapsulation theory and applications.pdf
Understanding_Digital_Forensics_Presentation.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing

Java Garbage Collection(GC)- Study

  • 1. Java GC Study Garbage Collection Dhanu Gupta
  • 2. Java GC Java objects are eligible for garbage collection (GC), which frees their memory and possibly associated resources, when they are no longer reachable Two stages of GC for an object finalization - runs finalize method on the object reclamation - reclaims memory used by the object
  • 3. GC Process Basic steps object is determined to be unreachable if object has a finalize method object is added to a finalization queue at some point it’s finalize method is invoked so the object can free associated resources object memory is reclaimed Issues with finalize methods makes every GC pass do more work if a finalize method runs for a long time, it can delay execution of finalize methods of other objects may create new strong references to objects that had none,preventing their GC run in a nondeterministic order no guarantee they will be called; app. may exit first
  • 4. Generational GC All of the GC algorithms used by Java are variations on the concept of generational GC • Generational GC assumes that the most recently created objects are the ones that are most likely to become unreachable soon for example, objects created in a method and only referenced by local variables that go out of scope when the method exits the longer an object remains reachable,the less likely it is to be eligible for GC soon (or ever) Objects are divided into “generations” or “spaces” Java categories these with the names “ young”, “tenured” and “perm” objects can move from one space to another during a GC
  • 5. Object Spaces Hold objects of similar ages or generations “ young” spaces hold recently created objects and can be GC’ed in a “minor” or “major” collection “ tenured” space hold objects that have survived some number of minor collections and can be GC’ed only in a major collection “ perm” space hold objects needed by the JVM, such as Class & Method objects, their byte code, and interned Strings GC of this space results in classes being “unloaded” Size of each space determined by current heap size(which can change during runtime) and several tuning options
  • 6. Young Spaces Eden space holds objects created after the last GC,except those that belong in the perm space during a minor collection, these objects are either GC’ed or moved to a survivor space Survivor spaces these spaces hold young objects that have survived at least one GC during a minor collection, these objects are either GC’ed or moved to the other survivor space Minor collections tend to be fast compared to major collections because only a subset of the objects need to be examined typically occur much more frequently than major collections
  • 7. When Does GC Occurs? Impacted by heap size “ If a heap size is small, collection will be fast but the heap will fill up more quickly,thus requiring more frequent collections.” “ Conversely, a large heap will take longer to fill up and thus collections will be less frequent,but they take longer.” Minor collections occur when a young space approaches being full Major collections occur when the tenured space approaches being full
  • 8. Tools to see Heap Jconsole Memory Analyzer
  • 9. Thanks Next I will shed More light on GC Properties.