File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Performance and the fly likes Heap memory usage increasing in Swing app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "Heap memory usage increasing in Swing app" Watch "Heap memory usage increasing in Swing app" New topic

Heap memory usage increasing in Swing app

Brady Diggs
Ranch Hand

Joined: Jun 26, 2008
Posts: 42
Hi all -
I've looked through the forums here and at Sun and have found some helpful info, but nothing that completely
explains what I'm seeing.
I'm running a Swing app in 1.6.
My VM args are:

I start the app and make no large data calls, just leave it running, sort of idling. I then start jconsole and watch the heap memory usage.
It begins ~10mb and over about 10 minutes increases to 75mb. Then it seems the garbage collector kicks in and the usage goes
back down to 10mb.

Here is the question: When I change the VM args to not have an initial setting (-Xms) the memory doesn't grow so large.
It goes up to about 20mb, then is garbage collected back down to 10mb.
Here are these VM args:

As you see, all I've done is remove the initial setting (-Xms512M).
When I look in jconsole at the "VM Summary" I don't see any initial setting at all. The compiler is configured to set it to max=512mb.
Maybe this is a problem?

I don't really care what the initial setting is as long as it's enough - what I want to know is: why the discrepancy in memory usage between my
two VM arg sets?
Does anyone have any insight into this? I would very much appreciate it, as I can't seem to find much documentation on it anywhere.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
The following book is very good and covers 99.9% of what you need to understand "Performance." Enjoy!

Performance Analysis for Java Websites

by ~ Stacy Joines , Ruth Willenborg, Ken Hygh

Paperback: 464 pages
Publisher: Addison-Wesley Professional
Language: English
ISBN-10: 0201844540
ISBN-13: 978-0201844542
Peter Johnson

Joined: May 14, 2008
Posts: 5852

The default for -Xms is fairly small, I don't even recall exactly what it is. JDK 6 usually adjusts the young generation size to be about 1/6 - 1/3 the size of the heap. So with a 512MB heap, you are seeing a 70MB young generation being filled and then garbage collected. Without -Xms set you are getting a smaller heap (let's say 64MB for discussions sake) so the young generation will be about 20MB and when it fills up the GC runs and cleans it.

The key, of course, is the actual heap size and young generation size. You can set command line options that will tell you the heap sizes during each collection. See my white papers for how to gather and make use of that information:
Java Garbage Collection Statistical Analysis 101
Java Garbage Collection Performance Analysis 201

JBoss In Action
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

Peter Johnson wrote:The default for -Xms is fairly small, I don't even recall exactly what it is.

2MB in JDK 5 and earlier. For JDK 6, it is the larger of 1/64th of the machine's physical memory on the machine or some reasonable minimum.
JDK 6 Garbage Collection Ergonomics

[How To Ask Questions On JavaRanch]
Brady Diggs
Ranch Hand

Joined: Jun 26, 2008
Posts: 42
Many, many thanks guys. You've offered some great insight and info.
I agree. Here's the link:
subject: Heap memory usage increasing in Swing app
It's not a secret anymore!