How to increase heap memory of your java application in Eclipse

13,658

Solution 1

If you go to Run -> Run Configuration in the Arguments Tab you will find the VM Arguments section where you can add this.

Sample Entry in VM Arguments

-Xms50M -Xmx128M

In Program Arguments you mention the arguments which will be passed to the Main Class.

Solution 2

Go to the eclipse.ini file in Eclipse directory.

 -startup
plugins/org.eclipse.equinox.launcher_1.3.0.v20130225-1645.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.200.v20130228-0336
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
-vmargs
-Xms1152m
-Xmx1152m

and change

**openFile
    -vmargs
    -Xms1152m
    -Xmx1152m**

accordingly.

Share:
13,658
Enrico
Author by

Enrico

Updated on June 14, 2022

Comments

  • Enrico
    Enrico almost 2 years

    can anyone teach me how to increase your heap size using arguments like -Xms1024m -Xmx1024m ? What is the difference of Program argument and VM argument?

  • Enrico
    Enrico over 10 years
    So which argument will be carried by the jar file? I'm wondering if the jar I am creating retains this max values i set in these argument
  • Ajay George
    Ajay George over 10 years
    @user2655077 There will be none which will be retained in the jar file that you create.To run your jar you need to pass these params from cmd line. java -Xms50M -Xmx128M -jar yourjar.jar
  • Ajay George
    Ajay George over 10 years
    OP is not asking about increasing eclipse's memory.
  • Enrico
    Enrico over 10 years
    I think I'm enlightened by that @Ajay George.. ^^
  • Master
    Master over 10 years
    Yes but sometimes you need to, to run large apps on Eclipse. To change it simply go to your eclipse directory and change in eclipse.ini it should work definitely.
  • Enrico
    Enrico over 10 years
    now my problem is how much memory should i allocate to my app? The server where this app is running has 32G memory..
  • Ajay George
    Ajay George over 10 years
    @user2655077 that would be a very difficult question to answer without knowing more about your app. Why don't you start by giving it 1G and see whether that suffices.
  • Enrico
    Enrico over 10 years
    i have allocated 2 gb and after few seconds it throws OOM
  • Ajay George
    Ajay George over 10 years
    try bumping it up to 4 G and enable -XX:-HeapDumpOnOutOfMemoryError to get the heap dump. Use it to analyze which objects are taking up most memory.