Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

OutOfMemoryError in a 1GB RAM machine  RSS feed

 
annie su
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Java application that needs to read in a big file (around 6M) after it starts up. The application is run in a 1GB machine. But from time to time it shows OutOfMemoryError exception.

I wonder why it cannot acquire more memory from the operating system when it needs to?

Is there other way to work around this?


Thanks in advance!
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Annie,

Welcome to JavaRanch!

The Java Virtual Machine (JVM) manages its own memory heap, and the maximum size of that pool is set when your program starts up. The default size depends on your platform and the Java version you're using, but it's often 64 MB. If you need a bigger heap, there are command line switches to set it. To run the class "ClassName" with a 150 megabyte heap, use

java -Xmx150m ClassName

And you can replace 150 with a larger number as needed.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's also possible that something else is using a LOT of memory.
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, also check that you don't have any object instances lurking around which cannot be cleared up by the garbage collector as these will hog memory. You can set any unused objects to null and also suggest running the garbage collector with System.gc()
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!