Latest Tutorials| Questions and Answers|Ask Questions?|Site Map

Home Help Java H Java Heap

Related Tutorials


Share on Google+Share on Google+

Java Heap

The JVM's heap stores all the objects generating by a running Java program.

Java Heap


The JVM's heap stores all the objects generating by a running Java program. Java uses the new operator to create objects and memory for new objects is allocated on the heap at run time. Garbage collection is the mechanism of automatically freeing up the memory contained by the objects that are no longer referenced by the program. This keeps the programmer free from having to keep track of when to free allocated memory, thereby preventing many potential bugs and headaches.

The mechanism "garbage collection" is implemented through an algorithm to the objects that are no longer needed by the program and can be thrown away.  "memory recycling." might be the more appropriate and up-to-date metaphor if an object is no longer referenced by the program, the heap space it occupies must be recycled so that the space is available for subsequent new objects. The garbage collector uses a mechanism to determine which objects are no longer referenced by the program and make available the heap space occupied by such unreferenced objects. Before freeing the memory occupied by the unreferenced objects, the garbage collector must run any finalizers of objects being freed.

A garbage collector may also perform a task of heap fragmentation while freeing up the unreferenced objects. Heap fragmentation is done through  normal program execution.




If you enjoyed this post then why not add us on Google+? Add us to your Circles

Liked it!  Share this Tutorial

Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 11, 2009

Related Tutorials

Discuss: Java Heap  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image