Set JVM to use memory size in eclipse

Source: Internet
Author: User


When you test a program that contains a large amount of data in Eclipse today, the following error is reported:

Java.lang.OutOfMemoryError:Java Heap Space

as you can see from the exception above, the amount of memory that theJVM needs to use exceeds the maximum memory we can allocate to the virtual machine. So the question turns into how to set the maximum memory for the JVM in Eclipse .

First,  try to modify the eclipse.ini file (This method does not work)

Locate the eclipse.ini file under the Eclipse directory and modify the following:

-xms512m

-xmx2048m

After modification, restart Eclipse , and the discovery does not work at all. After looking at some of the information, the original set of the minimum memory and maximum memory is not used for the JVM , this memory value contains the memory used by Eclipse itself.

Second, Modifying the JDK to use memory ( This method is possible)

Locate the window->preferences->java->installed JRE in Eclispe and click on the right Edit button, in the "default VM Arguments " option in the editing interface, fill in the following values.

-xms512m-xmx2048m

third, Modify Run configurations ( This method works )

Right-click on "Run as" and "Run configurations " on the code , and in the Arguments parameter, "VM Arguments: "Fill in the following values."

-xms512m-xmx2048m

Four, querying current JVM memory Code

The following is the code that queries the current JVM 's memory size and can test whether the JVM 's memory changes after the above settings. After adding configuration items for JVM memory, you do not need to restart Eclipse . The specific code is as follows:

Public class Testmemory {

    /**

* @param args

      */

public static void main (string[] args) {

System. out . println ( " Memory information :" + tomemoryinfo());

}

    /**

* gets The memory information of the current JVM

      *

* @return

      */

public static String tomemoryinfo () {

Runtime currruntime = runtime. GetRuntime ();

& nbsp;       int   nfreememory = (   int  

& nbsp;       int   ntotalmemory = (   int   ) ( Currruntime.totalmemory ()/1024/1024);

return nfreememory + "m/" + ntotalmemory +"M (free/total)"  ;

}

}

Set JVM to use memory size in eclipse

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.