jds
jds

Reputation: 8269

What does a memory leak look like in JConsole?

I am trying to use JConsole to see if I have a memory leak but do not know what to look for. If I had to guess, the memory usage should always go up, despite garbage collection, like this:

enter image description here

As you can see in my other SO question, I'm seeing a jagged edge, where the memory usage goes up—even if the browser is closed and no requests are hitting my local Tomcat server—and then go down.

enter image description here

What does a memory leak in Java "look like" in JConsole?

Upvotes: 2

Views: 2082

Answers (1)

Martin Claesson
Martin Claesson

Reputation: 31

I think the best way to learn what a memory leak looks like is to do an experiment. Try something like this to create a memory leak:

    Collection<Object> data = new LinkedList<>();
    while(true) {
        long[] canBeGarbageCollected = new long[10000];
        long[] canNotBeGarbageCollected = new long[100];
        data.add(Arrays.asList(canNotBeGarbageCollected));
    }

Besides JConsole you also have VisualVM that has a nice plugin called "Visual GC". Java Mission Control with Flight Recording can give you a lot of details. A very powerful tool exists on the command line as well:

jstat -gcutil -h20 $PID 1000

This will show that a memory leak will eventually lead to 100% Old space utilization (O) and the CPU will spend more and more time doing full garbage collections (FGCT)

Upvotes: 3

Related Questions