Your SlideShare is downloading. ×
  • Like
garbage collector
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply
Published

garbage collector

garbage collector

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
266
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
5
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 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. 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
  • 3. Features of Java programming language • Platform independent • Object oriented • Automatic garbage collection • Rich standard library
  • 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. Marking Before marking After marking Alive object Unreferenced object Memory object
  • 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. 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. Garbage collection • What is Garbage collection? – Memory management technique – Process of freeing objects – No longer referenced by the program
  • 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. 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. 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. Garbage collection algorithms • Reference counting • Tracing • Compacting • Copying • Generational • The train algorithm
  • 13. Reference counting • Keeps counts for each object • Count increases as the number of references increases • Eligible for gc when count becomes zero.
  • 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. 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. 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
  • 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: info@baabtra.com