garbage collector


Published on

garbage collector

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

garbage collector

  1. 1. 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
  2. 2. Garbage Collection in Java Abhishek H Menon abhishekmenon121989@gmail. com kmenon5 121989 menon
  3. 3. Features of Java programming language • Platform independent • Object oriented • Automatic garbage collection • Rich standard library
  4. 4. 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
  5. 5. Marking Before marking After marking Alive object Unreferenced object Memory object
  6. 6. 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
  7. 7. 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
  8. 8. Garbage collection • What is Garbage collection? – Memory management technique – Process of freeing objects – No longer referenced by the program
  9. 9. 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.
  10. 10. 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.
  11. 11. 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()
  12. 12. Garbage collection algorithms • Reference counting • Tracing • Compacting • Copying • Generational • The train algorithm
  13. 13. Reference counting • Keeps counts for each object • Count increases as the number of references increases • Eligible for gc when count becomes zero.
  14. 14. 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.
  15. 15. 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.
  16. 16. If this presentation helped you, please visit our page and like it. Thanks in advance. | |
  17. 17. 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: