Leave a comment

October 14, 2010 by huionn

Today, an incident of OutOfMemoryError was reported. I was so clueless by checking the log file. There was no suspicious activity when OutOfMemoryError happened.

I know Sun JDK provides dynamic heap dump (jconsole and jvisualvm) in Java SE 6, but I was not aware that -XX:+HeapDumpOnOutOfMemoryError is supported in JDK 1.4.2 Update 12 and Java SE 5 Update 7.

In order to understand -XX:+HeapDumpOnOutOfMemoryError, I wrote a simple program

public class OutOfMemory {
    public static void main(String[] args) {
        List l = new ArrayList();
        for (int i = 0; i < 10000000; i++) {
            l.add("hello world");

As expected, this silly program (with –Xmx64M) generated heap dump upon OutOfMemoryError.

Using Eclipse Memory Analyser (MAT), the culprit is obvious…

The thread java.lang.Thread @ 0xebe348b8 main keeps local variables with total size 30,536,720 (99.67%) bytes.

The memory is accumulated in one instance of "java.lang.Object[]" loaded by "<system class loader>".


MAT also provides dominator tree information (explained in http://dev.eclipse.org/blogs/memoryanalyzer/2008/05/27/automated-heap-dump-analysis-finding-memory-leaks-with-one-click/):


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: