SlideShare a Scribd company logo
Garbage Collection
In computer science, garbage collection (GC) is a
form of Automatic Memory Management.
The garbage collector attempts to reclaim the
memory occupied by objects that are no longer in
use by the program.
Garbage collection was invented by John McCarthy
around 1959 to abstract away manual memory
management in Lisp.
Static vs Dynamic memory allocation
Creating an array of ten integers in C (static)
int array[10];
Creating an array of integers in C (dynamic)
int * array = malloc(N * sizeof(int));
free(array);
In C++
Foo* fooPtr = new Foo()
delete fooPtr
Languages without GC
C, C++*, D*, Objective-C*,
Rust*
Languages
Languages wit GC
Java, Go, PHP, Python, Scala*,
Haskell, ….
Garbage Collection Algorithms
Reference Counting Mark and Sweep
Copy Collection
Generational Collection
Reference Counting
Keep an extra integer (“reference count”) to every
heap-allocated data structure.
● With a new reference ++refCount.
● When a reference disappears --refCount.
● If refCount == 0, then reclaim the storage
+ Easy to implement
+ Real Time cleanup
- Additional storage
- Speed: incr, decr
- Cycles not cleaned
C++, Objective-C, Rust,
PHP, Python….
Tracing Collectors vs Reference Counting
Mark and Sweep
Mark Phase: traverses all objects,
starting with roots, and marks every
object found as alive.
Sweep Phase: traverses all
objects, reclaim the storage of
unmarked objects.
+ Handles cycles
+ Easy to implement
- Stops the world**
- Scans the entire heap
Copy Collection
+ Handles cycles
+ Automatic Compaction
- Stops the world**
- Changes addresses
- 2nd half is unused
Generational Collection
● Most objects die young
● Newer objects usually point to older objects
+ Same as Copy (unidirectional)
+ Less Objects to Copy
+ Frequency of collection
+ Faster
- Stops the world**
- Complex to implement
Java Stack vs Heap
Pre and Post Java 8 Heap
Java Garbage Collectors
● Serial Collector - -XX:+UseSerialGC
● Parallel Collector - -XX:+UseParallelGC
● Concurrent Mark & Sweep Collector - -XX:+UseConcMarkSweepGC
● Garbage First (G1) Collector - -XX:+UseG1GC
Serial GC
● Stops the world
● Uses single thread
● Designed for single CPU small Heap apps
● Do not use it!
● Young Gen - Copy Collector
● Old Gen - Mark and Sweep
Parallel GC (The Default Collector)
● Stops the world
● Designed to work with multiple CPUs
● Uses multiple threads
● Expect high latencies when GC runs (-XX:MaxGCPauseMillis=<N>)
● Young Gen - Copy Collector
● Old Gen - Mark and Sweep
Concurrent Mark and Sweep (CMS) GC
● Stops the world (relatively short pauses)
● Designed to work with multiple CPUs
● Uses multiple threads
● Good for low latency apps
● Young Gen - Copy Collector
● Old Gen - Concurrent Mark-Sweep
Garbage First (G1) Collector
● Heap is split into (typically 2048) smaller regions
● Avoids collecting the entire heap at once, instead collects incrementally
○ The regions that contain the most garbage are collected first
● Soft real-time garbage collector (Predictable | Configurable STW)
● Compaction is relatively easy
● Uses multiple threads and is good for > 6G heap sizes. Java 9 Default GC.
● Young Gen - Copy Collector
● Old Gen - Concurrent Mark-Sweep
Minor GC vs Major GC vs Full GC
Minor GC cleans the Young Generation
Major GC cleans the Old Generation
Full GC cleans the Young and Old Generation
AdProxy Latency Issues
JVM Options to know
java -XX:+PrintFlagsFinal -version | grep HeapSize
uintx InitialHeapSize := 268435456 {product}
uintx MaxHeapSize := 4294967296 {product}
java -Xms256m -Xmx2048m
-XX:MaxGCPauseMillis=200
-XX:+PrintGCDetails -XX:+PrintGCDateStamps
Java Memory Leak
Hashmap keys without proper equals and hashcode
Maps or lists which are growing forever
Troubleshooting
UI Options: jconsole or jvisualvm.
Command Line:
jstat -gc -t processID 1s
jmap -heap processID
jmap -dump:live,format=b,file=heap.bin processID
jhat heap.bin
JVM Options: -XX:+PrintGCDetails-XX:+PrintGCDateStamps
Thank you!
Ad

More Related Content

What's hot (20)

Garbage collection
Garbage collectionGarbage collection
Garbage collection
Mudit Gupta
 
Single source Shortest path algorithm with example
Single source Shortest path algorithm with exampleSingle source Shortest path algorithm with example
Single source Shortest path algorithm with example
VINITACHAUHAN21
 
Garbage collection algorithms
Garbage collection algorithmsGarbage collection algorithms
Garbage collection algorithms
achinth
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
MOHIT DADU
 
Basic Garbage Collection Techniques
Basic  Garbage  Collection  TechniquesBasic  Garbage  Collection  Techniques
Basic Garbage Collection Techniques
An Khuong
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Java: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh EditionJava: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh Edition
moxuji
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
ShahDhruv21
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
Venkata Sreeram
 
Paging.ppt
Paging.pptPaging.ppt
Paging.ppt
infomerlin
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
Iffat Anjum
 
Branch and bound
Branch and boundBranch and bound
Branch and bound
Nv Thejaswini
 
Event handling
Event handlingEvent handling
Event handling
swapnac12
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
MsAnita2
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
Shraddha
 
Scheduling algorithms
Scheduling algorithmsScheduling algorithms
Scheduling algorithms
Chankey Pathak
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 
Deadlock dbms
Deadlock dbmsDeadlock dbms
Deadlock dbms
Vardhil Patel
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
Mudit Gupta
 
Single source Shortest path algorithm with example
Single source Shortest path algorithm with exampleSingle source Shortest path algorithm with example
Single source Shortest path algorithm with example
VINITACHAUHAN21
 
Garbage collection algorithms
Garbage collection algorithmsGarbage collection algorithms
Garbage collection algorithms
achinth
 
Critical section problem in operating system.
Critical section problem in operating system.Critical section problem in operating system.
Critical section problem in operating system.
MOHIT DADU
 
Basic Garbage Collection Techniques
Basic  Garbage  Collection  TechniquesBasic  Garbage  Collection  Techniques
Basic Garbage Collection Techniques
An Khuong
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
hodcsencet
 
Java: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh EditionJava: The Complete Reference, Eleventh Edition
Java: The Complete Reference, Eleventh Edition
moxuji
 
Topological Sorting
Topological SortingTopological Sorting
Topological Sorting
ShahDhruv21
 
DeadLock in Operating-Systems
DeadLock in Operating-SystemsDeadLock in Operating-Systems
DeadLock in Operating-Systems
Venkata Sreeram
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
Iffat Anjum
 
Event handling
Event handlingEvent handling
Event handling
swapnac12
 
Deadlock Avoidance - OS
Deadlock Avoidance - OSDeadlock Avoidance - OS
Deadlock Avoidance - OS
MsAnita2
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
Shraddha
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
kamal kotecha
 

Similar to Introduction to Garbage Collection (20)

(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag Session(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag Session
Jens Hadlich
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Jelastic Multi-Cloud PaaS
 
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
Haim Yadid
 
[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe
SAP HANA Cloud Platform
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Anna Shymchenko
 
G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?
C2B2 Consulting
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and you
Kai Koenig
 
Garbage First & You
Garbage First & YouGarbage First & You
Garbage First & You
ColdFusionConference
 
Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!
devObjective
 
2013 05 ny
2013 05 ny2013 05 ny
2013 05 ny
Sri Ambati
 
Jvm Architecture
Jvm ArchitectureJvm Architecture
Jvm Architecture
ThirupathiReddy Vajjala
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
Haim Yadid
 
Gpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cudaGpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cuda
Ferdinand Jamitzky
 
How I Sped up Complex Matrix-Vector Multiplication: Finding Intel MKL's "S
How I Sped up Complex Matrix-Vector Multiplication: Finding Intel MKL's "SHow I Sped up Complex Matrix-Vector Multiplication: Finding Intel MKL's "S
How I Sped up Complex Matrix-Vector Multiplication: Finding Intel MKL's "S
Brandon Liu
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
Jeremy Leisy
 
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Jelastic Multi-Cloud PaaS
 
An introduction to G1 collector for busy developers
An introduction to G1 collector for busy developersAn introduction to G1 collector for busy developers
An introduction to G1 collector for busy developers
Sanjoy Kumar Roy
 
Large-Scale, Semi-Automated Go Garbage Collection Tuning at Uber
Large-Scale, Semi-Automated Go Garbage Collection Tuning at UberLarge-Scale, Semi-Automated Go Garbage Collection Tuning at Uber
Large-Scale, Semi-Automated Go Garbage Collection Tuning at Uber
ScyllaDB
 
Programar para GPUs
Programar para GPUsProgramar para GPUs
Programar para GPUs
Alcides Fonseca
 
CodeStock - Exploring .NET memory management - a trip down memory lane
CodeStock - Exploring .NET memory management - a trip down memory laneCodeStock - Exploring .NET memory management - a trip down memory lane
CodeStock - Exploring .NET memory management - a trip down memory lane
Maarten Balliauw
 
(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag Session(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag Session
Jens Hadlich
 
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory UsageChoosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Choosing Right Garbage Collector to Increase Efficiency of Java Memory Usage
Jelastic Multi-Cloud PaaS
 
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
“Show Me the Garbage!”, Garbage Collection a Friend or a Foe
Haim Yadid
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Anna Shymchenko
 
G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?G1 Garbage Collector - Big Heaps and Low Pauses?
G1 Garbage Collector - Big Heaps and Low Pauses?
C2B2 Consulting
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and you
Kai Koenig
 
Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!
devObjective
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
Haim Yadid
 
Gpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cudaGpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cuda
Ferdinand Jamitzky
 
How I Sped up Complex Matrix-Vector Multiplication: Finding Intel MKL's "S
How I Sped up Complex Matrix-Vector Multiplication: Finding Intel MKL's "SHow I Sped up Complex Matrix-Vector Multiplication: Finding Intel MKL's "S
How I Sped up Complex Matrix-Vector Multiplication: Finding Intel MKL's "S
Brandon Liu
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
Jeremy Leisy
 
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...Elastic JVM  for Scalable Java EE Applications  Running in Containers #Jakart...
Elastic JVM for Scalable Java EE Applications Running in Containers #Jakart...
Jelastic Multi-Cloud PaaS
 
An introduction to G1 collector for busy developers
An introduction to G1 collector for busy developersAn introduction to G1 collector for busy developers
An introduction to G1 collector for busy developers
Sanjoy Kumar Roy
 
Large-Scale, Semi-Automated Go Garbage Collection Tuning at Uber
Large-Scale, Semi-Automated Go Garbage Collection Tuning at UberLarge-Scale, Semi-Automated Go Garbage Collection Tuning at Uber
Large-Scale, Semi-Automated Go Garbage Collection Tuning at Uber
ScyllaDB
 
CodeStock - Exploring .NET memory management - a trip down memory lane
CodeStock - Exploring .NET memory management - a trip down memory laneCodeStock - Exploring .NET memory management - a trip down memory lane
CodeStock - Exploring .NET memory management - a trip down memory lane
Maarten Balliauw
 
Ad

Recently uploaded (20)

Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025Adobe Lightroom Classic Crack FREE Latest link 2025
Adobe Lightroom Classic Crack FREE Latest link 2025
kashifyounis067
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
EASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License CodeEASEUS Partition Master Crack + License Code
EASEUS Partition Master Crack + License Code
aneelaramzan63
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Adobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest VersionAdobe Illustrator Crack FREE Download 2025 Latest Version
Adobe Illustrator Crack FREE Download 2025 Latest Version
kashifyounis067
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Ad

Introduction to Garbage Collection

  • 2. In computer science, garbage collection (GC) is a form of Automatic Memory Management. The garbage collector attempts to reclaim the memory occupied by objects that are no longer in use by the program. Garbage collection was invented by John McCarthy around 1959 to abstract away manual memory management in Lisp.
  • 3. Static vs Dynamic memory allocation Creating an array of ten integers in C (static) int array[10]; Creating an array of integers in C (dynamic) int * array = malloc(N * sizeof(int)); free(array); In C++ Foo* fooPtr = new Foo() delete fooPtr
  • 4. Languages without GC C, C++*, D*, Objective-C*, Rust* Languages Languages wit GC Java, Go, PHP, Python, Scala*, Haskell, ….
  • 5. Garbage Collection Algorithms Reference Counting Mark and Sweep Copy Collection Generational Collection
  • 6. Reference Counting Keep an extra integer (“reference count”) to every heap-allocated data structure. ● With a new reference ++refCount. ● When a reference disappears --refCount. ● If refCount == 0, then reclaim the storage + Easy to implement + Real Time cleanup - Additional storage - Speed: incr, decr - Cycles not cleaned C++, Objective-C, Rust, PHP, Python….
  • 7. Tracing Collectors vs Reference Counting
  • 8. Mark and Sweep Mark Phase: traverses all objects, starting with roots, and marks every object found as alive. Sweep Phase: traverses all objects, reclaim the storage of unmarked objects. + Handles cycles + Easy to implement - Stops the world** - Scans the entire heap
  • 9. Copy Collection + Handles cycles + Automatic Compaction - Stops the world** - Changes addresses - 2nd half is unused
  • 10. Generational Collection ● Most objects die young ● Newer objects usually point to older objects + Same as Copy (unidirectional) + Less Objects to Copy + Frequency of collection + Faster - Stops the world** - Complex to implement
  • 12. Pre and Post Java 8 Heap
  • 13. Java Garbage Collectors ● Serial Collector - -XX:+UseSerialGC ● Parallel Collector - -XX:+UseParallelGC ● Concurrent Mark & Sweep Collector - -XX:+UseConcMarkSweepGC ● Garbage First (G1) Collector - -XX:+UseG1GC
  • 14. Serial GC ● Stops the world ● Uses single thread ● Designed for single CPU small Heap apps ● Do not use it! ● Young Gen - Copy Collector ● Old Gen - Mark and Sweep
  • 15. Parallel GC (The Default Collector) ● Stops the world ● Designed to work with multiple CPUs ● Uses multiple threads ● Expect high latencies when GC runs (-XX:MaxGCPauseMillis=<N>) ● Young Gen - Copy Collector ● Old Gen - Mark and Sweep
  • 16. Concurrent Mark and Sweep (CMS) GC ● Stops the world (relatively short pauses) ● Designed to work with multiple CPUs ● Uses multiple threads ● Good for low latency apps ● Young Gen - Copy Collector ● Old Gen - Concurrent Mark-Sweep
  • 17. Garbage First (G1) Collector ● Heap is split into (typically 2048) smaller regions ● Avoids collecting the entire heap at once, instead collects incrementally ○ The regions that contain the most garbage are collected first ● Soft real-time garbage collector (Predictable | Configurable STW) ● Compaction is relatively easy ● Uses multiple threads and is good for > 6G heap sizes. Java 9 Default GC. ● Young Gen - Copy Collector ● Old Gen - Concurrent Mark-Sweep
  • 18. Minor GC vs Major GC vs Full GC Minor GC cleans the Young Generation Major GC cleans the Old Generation Full GC cleans the Young and Old Generation
  • 20. JVM Options to know java -XX:+PrintFlagsFinal -version | grep HeapSize uintx InitialHeapSize := 268435456 {product} uintx MaxHeapSize := 4294967296 {product} java -Xms256m -Xmx2048m -XX:MaxGCPauseMillis=200 -XX:+PrintGCDetails -XX:+PrintGCDateStamps
  • 21. Java Memory Leak Hashmap keys without proper equals and hashcode Maps or lists which are growing forever
  • 22. Troubleshooting UI Options: jconsole or jvisualvm. Command Line: jstat -gc -t processID 1s jmap -heap processID jmap -dump:live,format=b,file=heap.bin processID jhat heap.bin JVM Options: -XX:+PrintGCDetails-XX:+PrintGCDateStamps