Analyzing Memory Usage

Java makes it easy to generate and discard a large number of objects quickly, leading to inefficient use of memory. Quite often, new objects are created where other objects of the same or different class could be reused.

HPjmeter can estimate the number of objects created for each class from the number of calls to the constructors. Additional profiling options is Java 2 provide more direct control over printing of heap usage including the location in the program where all objects are created as well as size. Java 1.1 provides information about residual objects only.

In the early days of Java program development, people felt that explicit control of the Java heap was necessary. New features in Java 2 and fixing many of the defects in the garbage collector have now made explicit memory management of the Java heap detrimental to good application performance. In the HotSpot VM, explicit memory management will force a Full Garbage Collection when only a fast, Scavenge Garbage Collection may have been necessary.

For Java 1.1, you can assess the efficiency of your application's memory use by looking for the number of invocations and total time spent in the garbage collector. The garbage collector is identified by methods java.lang.Runtime.gc and java.lang.System.gc.

[Back]