Win a copy of Functional Reactive Programming this week in the Other Languages 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