Eclipse set JVM memory in
The following error was reported when testing the conversion of a document to a picture in eclipse today:
Java.lang.OutOfMemoryError:Java Heap Space |
As you can see from the exception above, the amount of memory that the JVM 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, attempt to modify the Eclipse.ini file (this method is not possible)
Locate the Eclipse.ini file under the Eclipse directory and modify the following:
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, Modify the JDK to use memory (this method works)
Locate the window->preferences->java->installed JRE in Eclispe, click the Edit button on the right, and in the "Default VM Arguments" option in the Edit interface, fill in the values below.
Third, Modify Run configurations (this method works)
Right-click on "Run as" and "Run Configurations" in the code and fill in the following values in "VM arguments:" In the arguments parameter.
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 (); int nfreememory = ( int ) (currruntime.freememory ()/1024/1024); int ntotalmemory = ( int ) (currruntime.totalmemory ()/1024/1024); return nfreememory + "m/" + ntotalmemory + "M (free/total)"; } } |
Eclipse Set JVM Memory