Monday 17 October 2011

Garbage collection in java , Garbage collection video free download











Click here for Garbage Collection video free download

Garbage Collection and its uses:

The objects that are not used and not referenced further in the program are treated as garbage and can be removed so that the memory is best utilized. That is , memory can be recycled and thus memory leaks does not occur.

It is difficult to know when the memory will be freed of an object in a process. Garbage collection relieves the programmer from the burden of freeing the allocated memory. Java does this job implicitly. 

We can advice the JVM to do garbage collection using gc() method of System class as follows:
System.gc();

Garbage collector is a low priority thread and is executed periodically whenever the processor is free. The garbage collector is a two phase process Mark and Sweep. Mark is the first phase, it marks the objects that are not used or referenced in the program.(known as garbage). In the next process sweep the unused objects are destroyed and the memory is freed.

One of the important features of Java is implicit memory management where memory is automatically created or destructed. For memory destruction, Java includes a concept called garbage collection. Even though every thing is implicit where programmer productivity increases , sometimes it is necessary to know the particulars of heap memory variable available, used and remaining;it may be necessary when we want to know the program size and availability of the memory.

No comments:

Post a Comment