tags:

views:

295

answers:

4

Well I am very new to Java and can't understand how am I supposed to set the virtual machine's size. I've built a small web applet that displays images. Sometimes the images can be pretty large, when this happens I get:

*Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space*

I've been trying to follow different instructions that I found on the Internet and have finally created this shortcut to Eclipse with the following command-line:

"C:\Documents and Settings\Dror Well\Desktop\temp\Eclipse\eclipse\eclipse\eclipse.exe" 
 -vmargs -vm "C:\Program Files\Java\jdk1.6.0_14\bin" 
 \"C:\Program Files\Java\jre6\bin\javaw.exe" -Xms256m -Xmx1024m

What am I missing? How should this be done?

A: 

The parameters should be passed to the JVM running your application, not the one running Eclipse. Try looking through the debug settings in Eclipse, there should be some place to put the -Xmx and -Xms parameters.

Tal Pressman
+5  A: 

In that line you have set the VM args to the Java process that Eclipse runs in. What you need to do for your application is to set the -Xmx512m (or however big you want it to be) for the application that you are running. You can do this from the Run dialog.

From the Run menu, choose 'Open Run Dialog'. In there, you should see on the left side a list of programs. If you have run it once already, yours should be listed in the Java Applications node. Select it and on the right panel, go to the Arguments tab. There will be a VM Arguments text box. Enter your -Xmx arg there.

akf
than its been hiding there all this time. G-d how I hate these little configuration settings, especially in new enviroments. Thank you all very much :) Have a good day =]
@vondip: would you care to accept this answer?
Ryan Fernandes
Regarding the command line, '-vm' is an argument telling the launcher where to find java, it should come before -vmargs. Everything after -vmargs are arguments that are passed through to the jvm. Also there's no point in listing two vm paths, at best the second one is just going to get ignored.
Andrew Niefer
A: 

Since the images can be pretty large, you should look at the following alternatives:

  1. Allocate more memory to the Java executable that will be launched by Eclipse (not Eclipse itself). This can be done via the VM arguments for the runtime configuration that you use to run the application in Eclipse.
  2. Switch to the parallel garbage collector, using the -XX:+UseParallelGC flag for the application (again, this is not for Eclipse). This wont help if you have large objects retained in memory for a long period of time.
Vineet Reynolds
A: 

For Eclipse you need to update the eclipse.ini file in order to set any JVM properties. Full details on where the file is and how to update it this link.

Carnell
The op is asking how to set the memory for an application launched by Eclipse, not the memory of Eclipse process itself. The Eclipse jvm properties can also be set on command line, like eclipse.exe -Xmx....
Hemal Pandya
Whoops i read that one completely wrong. That's what i get for working on things so late.
Carnell