This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OutofMemoryError Java Heap Space

 
Jim Ball
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Thanks,

Jim
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic