Download HeapInspector.zip(~73K)
A common frustration when developing large scale Java applications is the presence of "memory leaks." Memory leaks occur when a reference is prevented from being garbage collected by some active object holding a pointer to it. Over time, these leaks can cause a program to run out of memory. Tracking down rogue object references can be extremely tedious, especially within the complex (and often anonymous) relationships between objects in Sun's Swing library.
HeapInspector was written for the purpose of tracing back-references and identifying links which keep the object in memory. Reference browsing is accomplished by navigating one of two tree controls, one for forward references and one for back references. Additionally a node can be selected and then commanded to search the heap until the root reference is found.
HeapInspector is run as a bootstrap Java application which then invokes main() on the target application. No changes or instrumentation is required when debugging an application. HeapInspector includes support for JDK 1.1.8 and JDK 1.2 (or 1.3) though two native Win32 DLLs.
Below is a screen shot of the inspector running the SwingSet demo application. The main tree shows an instance count by class and allows back-tracing each reference. The lower left-hand tree shows the currently selected instance in the main tree, and allows searching that reference's member variables. The lower right-hand text pane shows additional information about the currently selected instance.
In addition to reference tracing, HeapInspector allows browsing the memory usage by all classes. Below is a screen shot of the Memory Usage panel.
| After downloading HeapInspector.zip, unzip
it to a destination directory, like c:\HeapInspector. You will see the following files have been extracted: |
||||||
HeapInspector.jar HeapInspector.dll HeapInspector2.dll inspect.bat inspect2.bat SimpleApp.class |
- java class and resource jar for the UI - JDK 1.1 native library - JDK 1.2 (or 1.3) native library - JDK 1.1 app startup script - JDK 1.2 (or 1.3) app startup script - a simple test application |
|||||
To try the HeapInspector on the sample application, edit the inspect.bat (inspect2.bat for JDK 1.2 or 1.3) file to fit your environment, and then type:
|
||||||
Q. How do I find the gc root of a reference?
A. Select the reference in the main reference tree and press the 'Find Root' button, or click on the reference with the right mouse button.Q. How can I test an applet using HeapInspector?
A. When using JDK 1.1, you can type:inspect sun.applet.AppletViewer <html page>
Q. When I run inspect.bat, I get the message: "Out of environment space."
A. The initial MS-DOS Prompt memory environment needs to be increased. You can do this by opening the properties for MS-DOS Prompt and changing the memory setting to a larger value, like 4096.Q. Can I debug my application using Microsoft's VM (jview)?
A. HeapInspector uses DLLs compiled specifically for Sun's JDK 1.1 and 1.2.
Microsoft's VM uses a different (and privately defined) heap layout and won't work with HeapInspector.Q. I have the HeapInspector.jar in my classpath and I'm using jdk1.2. When I do: inspect2 SimpleApp I get a NoClassDefFoundError: com/frisky4/debug/HeapInspectorMain
A. The Heap Inspector doesn't look at the classpath environment variable when called from inspect2.bat. It loads in HeapInspector.jar by looking in the directory specified by line 6 in inspect2.bat:
set DEBUG_HOME2=c:\HeapInspector
Make sure that the variable is edited to point to the directory where the HeapInspector was unzipped.Q. When running inspect2.bat with JDK 1.3, I get the following error message:
A device attached to the system is not functioning
or
The specified procedure could not be found
A. This is caused because JDK 1.3 uses the "hotspot" VM by default. If you download the latest version of HeapInspector.zip, this problem has been fixed by using the "-classic" argument in the inspect2.bat file.
Send your questions to moellep@yahoo.com