• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

OutOfMemoryError in a 1GB RAM machine

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's also possible that something else is using a LOT of memory.
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()
 
Liar, liar, pants on fire! refreshing plug:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic