Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.OutOfMemoryError

 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I keep getting this error java.lang.OutOfMemoryError. How do i check how much memory the JVM is using and how do change the memory of the JVM? Thanks in advance?
 
Purushoth Thambu
Ranch Hand
Posts: 425
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can find how much memory JVM is using and available free memory using
java.lang.Runtime class api's totalMemory() and freeMemory(). I am not sure how one can increase the memory for the JVM. It will be more specific to host OS.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could set it with -X options
if you type java -X it will show you the help, there are two options
-Xms set initial Java heap size and -Xmx set maximum Java heap size.
 
Luke Knightley
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's worth mentioning that memory leaks are definitely not impossible in Java. If in your code you (for example) add Objects to a Collection without ever removing them, you will eventually run out of memory. As mentioned in the previous post the -Xms<size> (initial Java heap size) and -Xmx<size> (maximum Java heap size) allow you to set the heap size.
 
David Ulicny
Ranch Hand
Posts: 724
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also static Collection is dangerous.
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also set this permanently in the Java plugin e.g. on windows Start --> Settings --> control panel --> Java plugin. Click the advanced tab and then stick it in the Java Runtime Parameters field something like

-Xms32m -Xmx256m
 
kevin comario
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help. I'm still trying to figure out what to do but all this points me in the right direction.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic