aspose file tools*
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
Author

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:
-Xms512M
-Xmx1024M
-Dmsroot="${workspace_loc:/App/run}"
-Djava.library.path="${workspace_loc:/App/run/bin}"

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:
-Xmx1024M
-Dmsroot="${workspace_loc:/App/run}"
-Djava.library.path="${workspace_loc:/App/run/bin}"

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
author
Bartender

Joined: May 14, 2008
Posts: 5827
    
    7

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
at http://www.cmg.org/cgi-bin/search.cgi?q=java+peter+johnson&x=30&y=10


JBoss In Action
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8908
    
    8

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


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[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: http://aspose.com/file-tools
 
subject: Heap memory usage increasing in Swing app