Garbage Collection

  • How objects are stored: The JVM's heap stores all objects created by an executing Java program. Objects are created by Java's "new" operator, and memory for new objects is allocated on the heap at run time. Garbage collection is the process of automatically freeing objects that are no longer referenced by the program. 
  • Initiating garbage collection: You can directly run the garbage collector whenever you want to and it will be schedule in due time.. by calling Runtime.gc() . The garbage collector informs your object when it is about to be garbage collected. The garbage collector runs in low-memory situations.
  • Eligibility for garbage collection: An Object becomes eligible for Garbage collection or GC if its not reachable from any live threads or any static refrences in other words you can say that an object becomes eligible for garbage collection if its all references are null. 
  • Cyclic dependencies: Cyclic dependencies are not counted as reference so if Object A has reference of object B and object B has reference of Object A and they don't have any other live reference then both Objects A and B will be eligible for Garbage collection. Read more: http://javarevisited.blogspot.in/2011/04/garbage-collection-in-java.html
  • Garbage collection algorithms: Two basic approaches to distinguishing live objects from garbage are reference counting and tracing. Reference counting garbage collectors distinguish live objects from garbage objects by keeping a count for each object on the heap. The count keeps track of the number of references to that object. Tracing garbage collectors, on the other hand, actually trace out the graph of references starting with the root nodes. Objects that are encountered during the trace are marked in some way. After the trace is complete, unmarked objects are known to be unreachable and can be garbage collected. 

Comments

Popular posts from this blog

jQgrid reload with new data

Rich Client based UI technologies- A Comparison of Thick Client UI tools

OSS and BSS Systems