Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in Java by (5.3k points)

I am writing a client-side Swing application (graphical font designer) on Java 5. Recently, I am running into java.lang.OutOfMemoryError: Java heap space error because I am not being conservative on memory usage. The user can open unlimited number of files, and the program keeps the opened objects in the memory. After a quick research I found Ergonomics in the 5.0 Java Virtual Machine and others saying on Windows machine the JVM defaults max heap size a 64mb

Given this situation, how should I deal with this constraint?

I could increase the max heap size using command line option to java, but that would require figuring out available RAM and writing some launching program or script. Besides, increasing to some finite max does not ultimately get rid of the issue.

I could rewrite some of my code to persist objects to file system frequently (using database is the same thing) to free up the memory. It could work, but it's probably a lot work too.

If you could point me to details of above ideas or some alternatives like automatic virtual memory, extending heap size dynamically, that will be great.

1 Answer

0 votes
by (119k points)

To specify per project how much heap space your project wants

Following is for Eclipse Helios/Juno/Kepler:

Right mouse click on

  Run As -> Run Configuration -> Arguments -> Vm Arguments, 

then add this

-Xmx2048m

If you want to learn Java from Industry experts, then check out this Java Certification by Intellipaat.

Related questions

0 votes
1 answer
0 votes
1 answer
+9 votes
2 answers
0 votes
1 answer
0 votes
1 answer

Browse Categories

...