SlideShare a Scribd company logo
garbage collector
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
Garbage Collection in Java
Abhishek H Menon
abhishekmenon121989@gmail.
com
www.facebook.com/abhishe
kmenon5
twitter.com/abhishekmenon
121989
in.linkedin.com/in/abhishekh
menon
Features of Java programming language
• Platform independent
• Object oriented
• Automatic garbage collection
• Rich standard library
Automatic garbage collection
• Process of looking at heap memory, identifying which objects
are in use and which are not, and deleting the unused objects.
• In programming languages like C, CPP allocating and deallocating
is a manual process, but in Java garbage collector automatically
do allocation and deallocation.
• For performing this task of garbage collection, there are two
steps
– Marking
– Normal deletion
– Deletion with compacting
Marking
Before marking
After marking
Alive object
Unreferenced object
Memory object
Normal Deletion
Memory allocator holds a list of references to free
spaces, and searches for free spaces and allocated
memory sequentially then on.
Memory space
Deletion with compacting
After normal
deletion with
compacting
Memory allocation holds the reference to the
beginning of free space and allocated memory
sequentially then on
Garbage collection
• What is Garbage collection?
– Memory management technique
– Process of freeing objects
– No longer referenced by the program
Garbage collection
• Why Garbage collection?
– Free unreferenced objects.
– Relieves programmer from manual freeing the
memory.
– Helps in ensuring program integrity.
– Disadvantages
• Extra Overhead.
• Less control over scheduling of CPU time.
Garbage collection in java
• Purpose?
– Find and delete unreachable objects.
– Free space as much as possible.
• When?
– GC is under control of JVM.
– One can request but no guarantees.
• How?
– Discovery of unreachable objects.
– With the help of Algorithms.
Garbage collection in java
• Ways of making an object eligible for
collection
– Nulling a reference
– Reassigning a reference variable
– Isolating a reference variable
• Forcing Garbage collection
– Methods available to perform GC
– Only requests and no demands
– Using runtime class
– Using static methods like System.gc()
Garbage collection algorithms
• Reference counting
• Tracing
• Compacting
• Copying
• Generational
• The train algorithm
Reference counting
• Keeps counts for each object
• Count increases as the number of references
increases
• Eligible for gc when count becomes zero.
Tracing
• Traverses through the graph
• Starts from the root node
• Marking is done
– By setting flags in object themselves
– By setting flags in separate bitmaps
• Unmarked objects to be unreachable
• Also known as Mark and Sweep alg.
Finalize() method
• This method is called before the garbage
collector claims the object
• Available for all the classes in java
• Defined in java.lang.Object
• Purpose of this method is to perform clean up
activity ie, releasing system resources if
held, close the connection if open.
• After executing this method, the program gets
for garbage collection.
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

More Related Content

PDF
Java Collection framework
PPTX
Heap Sort in Design and Analysis of algorithms
PPTX
PPTX
Packages in java
PPTX
PDF
DBMS LECTURE NOTES FOR AKTU
PPTX
Garbage collection
PPTX
Design Pattern
Java Collection framework
Heap Sort in Design and Analysis of algorithms
Packages in java
DBMS LECTURE NOTES FOR AKTU
Garbage collection
Design Pattern

What's hot (20)

PDF
Pipes & Filters Architectural Pattern
PPT
Data Structures- Part5 recursion
PPTX
9 big o-notation
ODP
Garbage collection
PPTX
Component and Deployment Diagram - Brief Overview
PPT
Design and Analysis of Algorithms
PPTX
Implementation of lexical analyser
PPTX
Garbage collection in .net (basic level)
PPTX
Inheritance in java
PPTX
Means End Analysis (MEA) in Artificial.pptx
PPTX
Association agggregation and composition
PPTX
Dns presentation
PPT
Algorithm analysis
PPTX
Types of Parser
PPTX
DBMS - RAID
PPTX
uninformed search part 1.pptx
PDF
Introduction to Garbage Collection
PPTX
LINQ in C#
PPTX
Heap Memory Management.pptx
PPT
Servlet life cycle
Pipes & Filters Architectural Pattern
Data Structures- Part5 recursion
9 big o-notation
Garbage collection
Component and Deployment Diagram - Brief Overview
Design and Analysis of Algorithms
Implementation of lexical analyser
Garbage collection in .net (basic level)
Inheritance in java
Means End Analysis (MEA) in Artificial.pptx
Association agggregation and composition
Dns presentation
Algorithm analysis
Types of Parser
DBMS - RAID
uninformed search part 1.pptx
Introduction to Garbage Collection
LINQ in C#
Heap Memory Management.pptx
Servlet life cycle
Ad
Ad

Similar to garbage collector (20)

PPTX
Chronicles Of Garbage Collection (GC)
PDF
Garbage Collection in Java.pdf
PPTX
DESTRUCTORS in Java for a lecture to understand
PPTX
Garbage collection in C#,important topic
PDF
Everything you need to know about GraalVM Native Image
PPTX
Building High Available and Scalable Machine Learning Applications
PPTX
GC in C#
PDF
Garbage collection 介紹
PPTX
.NET UY Meetup 7 - CLR Memory by Fabian Alves
PPTX
Thread in java.pptx
PPTX
G13_Resource_Management_Presentation_DevC.pptx
PPTX
Javasession10
PDF
Managing Memory in Swift (Yes, that's a thing)
PPTX
02D-Memory Management in Java.pptx
PDF
Java Garbage Collection - How it works
KEY
OOP in JS
PDF
Advanced debugging
PPTX
Client Best Practices
PPTX
Coding Best Practices For Memory Management
PPTX
Session 09 - OOPS
Chronicles Of Garbage Collection (GC)
Garbage Collection in Java.pdf
DESTRUCTORS in Java for a lecture to understand
Garbage collection in C#,important topic
Everything you need to know about GraalVM Native Image
Building High Available and Scalable Machine Learning Applications
GC in C#
Garbage collection 介紹
.NET UY Meetup 7 - CLR Memory by Fabian Alves
Thread in java.pptx
G13_Resource_Management_Presentation_DevC.pptx
Javasession10
Managing Memory in Swift (Yes, that's a thing)
02D-Memory Management in Java.pptx
Java Garbage Collection - How it works
OOP in JS
Advanced debugging
Client Best Practices
Coding Best Practices For Memory Management
Session 09 - OOPS

More from baabtra.com - No. 1 supplier of quality freshers (20)

PPTX
Agile methodology and scrum development
PDF
Acquiring new skills what you should know
PDF
Baabtra.com programming at school
PDF
99LMS for Enterprises - LMS that you will love
PPTX
Chapter 6 database normalisation
PPTX
Chapter 5 transactions and dcl statements
PPTX
Chapter 4 functions, views, indexing
PPTX
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
PPTX
Chapter 1 introduction to sql server
PPTX
Chapter 1 introduction to sql server
Agile methodology and scrum development
Acquiring new skills what you should know
Baabtra.com programming at school
99LMS for Enterprises - LMS that you will love
Chapter 6 database normalisation
Chapter 5 transactions and dcl statements
Chapter 4 functions, views, indexing
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 1 introduction to sql server
Chapter 1 introduction to sql server

Recently uploaded (20)

PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Approach and Philosophy of On baking technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
August Patch Tuesday
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
Getting Started with Data Integration: FME Form 101
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
Encapsulation theory and applications.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PPTX
1. Introduction to Computer Programming.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
cloud_computing_Infrastucture_as_cloud_p
Hindi spoken digit analysis for native and non-native speakers
Approach and Philosophy of On baking technology
Digital-Transformation-Roadmap-for-Companies.pptx
SOPHOS-XG Firewall Administrator PPT.pptx
August Patch Tuesday
OMC Textile Division Presentation 2021.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Getting Started with Data Integration: FME Form 101
Group 1 Presentation -Planning and Decision Making .pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
1 - Historical Antecedents, Social Consideration.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Encapsulation theory and applications.pdf
Encapsulation_ Review paper, used for researhc scholars
Heart disease approach using modified random forest and particle swarm optimi...
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
1. Introduction to Computer Programming.pptx
MIND Revenue Release Quarter 2 2025 Press Release

garbage collector

  • 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 3. Garbage Collection in Java Abhishek H Menon abhishekmenon121989@gmail. com www.facebook.com/abhishe kmenon5 twitter.com/abhishekmenon 121989 in.linkedin.com/in/abhishekh menon
  • 4. Features of Java programming language • Platform independent • Object oriented • Automatic garbage collection • Rich standard library
  • 5. Automatic garbage collection • Process of looking at heap memory, identifying which objects are in use and which are not, and deleting the unused objects. • In programming languages like C, CPP allocating and deallocating is a manual process, but in Java garbage collector automatically do allocation and deallocation. • For performing this task of garbage collection, there are two steps – Marking – Normal deletion – Deletion with compacting
  • 6. Marking Before marking After marking Alive object Unreferenced object Memory object
  • 7. Normal Deletion Memory allocator holds a list of references to free spaces, and searches for free spaces and allocated memory sequentially then on. Memory space
  • 8. Deletion with compacting After normal deletion with compacting Memory allocation holds the reference to the beginning of free space and allocated memory sequentially then on
  • 9. Garbage collection • What is Garbage collection? – Memory management technique – Process of freeing objects – No longer referenced by the program
  • 10. Garbage collection • Why Garbage collection? – Free unreferenced objects. – Relieves programmer from manual freeing the memory. – Helps in ensuring program integrity. – Disadvantages • Extra Overhead. • Less control over scheduling of CPU time.
  • 11. Garbage collection in java • Purpose? – Find and delete unreachable objects. – Free space as much as possible. • When? – GC is under control of JVM. – One can request but no guarantees. • How? – Discovery of unreachable objects. – With the help of Algorithms.
  • 12. Garbage collection in java • Ways of making an object eligible for collection – Nulling a reference – Reassigning a reference variable – Isolating a reference variable • Forcing Garbage collection – Methods available to perform GC – Only requests and no demands – Using runtime class – Using static methods like System.gc()
  • 13. Garbage collection algorithms • Reference counting • Tracing • Compacting • Copying • Generational • The train algorithm
  • 14. Reference counting • Keeps counts for each object • Count increases as the number of references increases • Eligible for gc when count becomes zero.
  • 15. Tracing • Traverses through the graph • Starts from the root node • Marking is done – By setting flags in object themselves – By setting flags in separate bitmaps • Unmarked objects to be unreachable • Also known as Mark and Sweep alg.
  • 16. Finalize() method • This method is called before the garbage collector claims the object • Available for all the classes in java • Defined in java.lang.Object • Purpose of this method is to perform clean up activity ie, releasing system resources if held, close the connection if open. • After executing this method, the program gets for garbage collection.
  • 17. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 18. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com