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

OutofMemoryError Java Heap Space

Jim Ball

Joined: Dec 05, 2006
Posts: 8
To correct this error I can simply increase the JVM's heap size. My question is how can I increase the JVM's heap size efficiently so I do not over allocate? Are there steps to follow to see approximately how much heap size (memory space) I need for my program? Any assistance would be greatly appreciated.


Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
One quick way to get an idea how much memory your program uses is to invoke java using the -verbose:gc option:

java -verbose:gc MyClass

You will get messages to standard output describing how the memory use goes up and down, and how it's affected by GC. However note that it's always possible that GC could have collected more, at any given time. If you over-allocate memory, it's possible the JVM will use it just because it's available, and the GC won't necessarily try so hard to free up memory until you approach the limit. So you should also experiment a bit with changing the -mx parameter, just to see what happens.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: OutofMemoryError Java Heap Space
It's not a secret anymore!