This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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
Don't get me started about those stupid light bulbs.
subject: OutofMemoryError Java Heap Space
Similar Threads
Increase JVM heap size of eclipse
Exectuion throwing Out of Memory exception
Command line options in TextPad
Eclipse 3.2 Increase Heap?
Out of memory error