Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

HOME

java certification tutorial

chapter1 | chapter2 | chapter3 | chapter4 | chapter5 | chapter6 |

chapter7 | chapter8 | chapter9 | chapter10 | chapter11 |

 

Chapter7: Garbage Collection

 

  • Java handles a memory management for you.
  • This is achieved by a process called Garbage Collection.
  • Garbage Collection process runs as a low priority thread.
  • The garbage collector only knows how to release memory allocated with new.

*Any object is eligible for garbage collection when your program can no longer reference it.

*Local variables are eligible for garbage collection when the variables go out of scope.

*An object is available for garbage collection if it is set to 'null'.

*All immutable objects are candidates for garbage collection after their reuse.

*The virtual machine only perform garbage collection if it is in short of memory.

*Garbage Collection is guaranteed with the objects with no reference.

*We cannot exactly predict when the garbage collection will occur.

*you can explicitly make a call to the garbage collection by calling

System.gc();

or

Runtime.getRuntime().gc();

but this doesnot guarantee when it will happen.

*If you want to perform some task when your object is about to be garbage collected, you can override java.lang.Object method called finalize().

*finilize() method is protected, does not return a value and throws a Throwable object

i.e,protected void finalize() throws Throwable.

*Garbage collector before performing cleanup calls the finalize().

*if a finalize() method exists it is guaranteed to be executed only once.

* finalize() should be used for closing files and other resources which you think are not garbage collected.

*An object is available for gc ,if you have either set it to null or you have redirected the variable that was originally referring to it, so that it now refers to a different object ( this is incase of immutable objects such as String object)

*To make sure that an object to be garbage collected remove all references to it.

take an exam on this topic here
Please submit your ideas on this topic here
sign my guest book here

 

 

Copyrights anilbachi.8m.com

All rights reserved