Skip Headers
Previous
Previous
 
Next
Next

Studying Heap Usage in Verbose Outputs

An early sign of a memory leak in a Java application is increasing heap usage. An old space garbage collection (old collection) removes all unused objects from the heap. Normally, the heap usage after each old collection should be fairly constant over time, but if the application erroneously keeps more and more objects alive, the heap usage after old collections increases for each garbage collection.

A simple way to monitor the heap usage is to view verbose garbage collection outputs. To do this, you simply start the JRockit JVM with the -Xverbose:gc option and then watch the output for a while, as shown in this output example:



[memory ] 2.703-2.729: GC 262144K->3904K (262144K), 25.857 ms
[memory ] 3.901-3.940: GC 262144K->10820K (262144K), 38.835 ms
[memory ] 4.857-4.913: GC 262144K->19606K (262144K), 56.011 ms
[memory ] 5.780-5.878: GC 262144K->28424K (262144K), 97.406 ms

The value after the arrow (->) is the heap usage after the garbage collection. The preceding example contains only old collections. You can clearly see that the heap usage after garbage collections is constantly growing in this example.

This is however a cumbersome way to monitor heap usage over longer period of time. The Management Console provides graphical tools for monitoring the heap usage over time, as described in "Studying Heap Usage in the Management Console".