javaeclipsememory-size

Xmx is 3072m but Runtime.getRuntime().totalMemory() returns 59mb


I am using eclipse EE in ubuntu by downloading the .tar.gz file from eclipse website and extracting in my home directory. I set the -Xmx to 3072m in the eclipse.ini. Here it is:

-startup
plugins/org.eclipse.equinox.launcher_1.1.0.v20100507.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.1.R36x_v20100810
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vmargs
-Dosgi.requiredJavaVersion=1.5
-XX:MaxPermSize=256m
-Xms2048m
-Xmx3072m

But when I am trying to see my total memory by

Runtime.getRuntime().totalMemory()

It is returning 62193664 that is 59mb. I also tried to launch eclipse from terminal setting vmagrs, but nothing changed. I don't know what is happening. How can I set the heap size? My total ram is 4gb and I using 64bit Ubuntu with 64bit eclipse. Any information will be very helpful to me.


Solution

  • 1) The Runtime.getRuntime().totalMemory() does not return the maximum allowed heap size.

    2) I'm not sure how do you run Runtime.getRuntime().totalMemory() but I guess you do that from within your Eclipse in a Java application. In this case you execute the call in another JVM which does not inherit properties from your eclipse.ini file. If you want to determine the initial and max heap size for it you can go to Run->Run Configurations.... Click on your current run configuration and in the right pane click on the Arguments tab. There you may specify the VM arguments, e.g.:

    -Xms64m
    -Xmx1024m 
    

    Afterwards you may continue experimenting with the Runtime. eclipse.ini configures the resources for the Eclipse IDE not for the Java application that you run.

    Cheers!