SlideShare a Scribd company logo
1 of 23
Download to read offline
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!

More Related Content

What's hot

Time and space complexity
Time and space complexityTime and space complexity
Time and space complexityAnkit Katiyar
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen ProblemSukrit Gupta
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardAnimesh Chaturvedi
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage CollectionEelco Visser
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSGayathri Gaayu
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemMadhu Bala
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IMohamed Loey
 
Memory allocation (4)
Memory allocation (4)Memory allocation (4)
Memory allocation (4)rockymani
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithmsGanesh Solanke
 
Operating system paging and segmentation
Operating system paging and segmentationOperating system paging and segmentation
Operating system paging and segmentationhamza haseeb
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating SystemsRitu Ranjan Shrivastwa
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
data structures- back tracking
data structures- back trackingdata structures- back tracking
data structures- back trackingAbinaya B
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notationsNikhil Sharma
 

What's hot (20)

Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
P, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-HardP, NP, NP-Complete, and NP-Hard
P, NP, NP-Complete, and NP-Hard
 
Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Deadlock ppt
Deadlock ppt Deadlock ppt
Deadlock ppt
 
CS8391 Data Structures Part B Questions Anna University
CS8391 Data Structures Part B Questions Anna UniversityCS8391 Data Structures Part B Questions Anna University
CS8391 Data Structures Part B Questions Anna University
 
DESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMSDESIGN AND ANALYSIS OF ALGORITHMS
DESIGN AND ANALYSIS OF ALGORITHMS
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
 
Greedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack ProblemGreedy Algorithm - Knapsack Problem
Greedy Algorithm - Knapsack Problem
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Memory allocation (4)
Memory allocation (4)Memory allocation (4)
Memory allocation (4)
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Operating system paging and segmentation
Operating system paging and segmentationOperating system paging and segmentation
Operating system paging and segmentation
 
Process synchronization in Operating Systems
Process synchronization in Operating SystemsProcess synchronization in Operating Systems
Process synchronization in Operating Systems
 
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
 
Unit 3 daa
Unit 3 daaUnit 3 daa
Unit 3 daa
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
data structures- back tracking
data structures- back trackingdata structures- back tracking
data structures- back tracking
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 

Similar to Introduction to Garbage Collection

(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag Session(JVM) Garbage Collection - Brown Bag Session
(JVM) Garbage Collection - Brown Bag SessionJens 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 UsageJelastic 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 FoeHaim 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 youKai 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 CollectionHaim Yadid
 
Gpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cudaGpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cudaFerdinand 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 "SBrandon Liu
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance TuningJeremy 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 developersSanjoy 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 UberScyllaDB
 
Compiler basics: lisp to assembly
Compiler basics: lisp to assemblyCompiler basics: lisp to assembly
Compiler basics: lisp to assemblyPhil Eaton
 

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
 
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
 
“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
 
[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe[BGOUG] Java GC - Friend or Foe
[BGOUG] Java GC - Friend or Foe
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
 
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?
 
Garbage First & You
Garbage First & YouGarbage First & You
Garbage First & You
 
Garbage First and you
Garbage First and youGarbage First and you
Garbage First and you
 
Garbage First and You!
Garbage First and You!Garbage First and You!
Garbage First and You!
 
2013 05 ny
2013 05 ny2013 05 ny
2013 05 ny
 
Jvm Architecture
Jvm ArchitectureJvm Architecture
Jvm Architecture
 
Let's talk about Garbage Collection
Let's talk about Garbage CollectionLet's talk about Garbage Collection
Let's talk about Garbage Collection
 
Gpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cudaGpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cuda
 
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
 
JVM Performance Tuning
JVM Performance TuningJVM Performance Tuning
JVM Performance Tuning
 
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...
 
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
 
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
 
Programar para GPUs
Programar para GPUsProgramar para GPUs
Programar para GPUs
 
Compiler basics: lisp to assembly
Compiler basics: lisp to assemblyCompiler basics: lisp to assembly
Compiler basics: lisp to assembly
 

Recently uploaded

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfproinshot.com
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfVishalKumarJha10
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 

Recently uploaded (20)

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 

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