Memory

 

 

+

Search Tips   |   Advanced Search

 

Java does not require, or allow, programmers to explicitly allocate and reclaim memory. The JVM will allocate memory when a new object is created, and will reclaim the memory once there are no more references to the object.

Java does not allow pointer arithmetic. Memory deallocation is performed by a thread executing in the JVM called the garbage collector (GC).

The garbage collection algorithm used for is not specified in the JVM specification. Different JVM implementations may use different GC algorithms.

However, all of these algorithms require the sweeping of memory to identify objects that are no longer referenced. Most also involve a compaction phase where referenced objects are copied to a particular area of memory to reduce fragmentation.

More details about garbage collection can be found in...

"Improving Java Application Performance and Scalability by Reducing Garbage Collection Times and Sizing Memory"

There is also a JDK 1.4.1 version of the article

Creating an object consumes system resources, because the JVM must allocate memory and initialize the object.

Reclaiming memory using the garbage collector uses CPU time.

Garbage collection occurs asynchronously when free memory reaches threshold values, and it cannot be explicitly scheduled programmatically. A call to the System.gc() method will request that the JVM performs garbage collection. However, this is not guaranteed to happen immediately or within any specified time period.

To minimize memory usage, particularly object creation and destruction...