標籤:java out of memory heap space
最近在eclipse-jee-luna-SR2-win32開發環境(java version:1.7.0_60)下匯入JEECG3.5.2開源項目過程中發現在build workspace過程中報Internal Error,查看workspace檔案夾下的.metadata檔案夾中的.log檔案發現有下面的錯誤:
!ENTRY org.eclipse.core.jobs 4 2 2015-08-04 18:37:10.621
!MESSAGE An internal error occurred during: "Building workspace".
!STACK 0
java.lang.OutOfMemoryError: Java heap space
at org.eclipse.wst.jsdt.internal.core.index.DiskIndex.readStreamChars(DiskIndex.java:884)
at org.eclipse.wst.jsdt.internal.core.index.DiskIndex.readCategoryTable(DiskIndex.java:632)
at org.eclipse.wst.jsdt.internal.core.index.DiskIndex.addQueryResults(DiskIndex.java:199)
at org.eclipse.wst.jsdt.internal.core.index.Index.query(Index.java:154)
at org.eclipse.wst.jsdt.internal.core.search.matching.FieldPattern.queryIn(FieldPattern.java:330)
at org.eclipse.wst.jsdt.internal.core.search.matching.InternalSearchPattern.findIndexMatches(InternalSearchPattern.java:92)
at org.eclipse.wst.jsdt.internal.core.search.matching.OrPattern.findIndexMatches(OrPattern.java:59)
at org.eclipse.wst.jsdt.internal.core.search.matching.MatchLocator.findIndexMatches(MatchLocator.java:407)
at org.eclipse.wst.jsdt.internal.core.search.PatternSearchJob.search(PatternSearchJob.java:116)
at org.eclipse.wst.jsdt.internal.core.search.PatternSearchJob.execute(PatternSearchJob.java:66)
at org.eclipse.wst.jsdt.internal.core.search.processing.JobManager.performConcurrentJob(JobManager.java:280)
......
在網上有不少關於這個錯誤的解決方案,試了幾個都沒有效果。大致思路都是通過修改Eclipse的記憶體配置的方法,通過修改Eclipse喜好設定中Java虛擬機器的參數來解決的。可是究竟應該修改成多少,卻有許多不同的說法。650) this.width=650;" title="JVM參數設定.png" style="float:left;" src="http://s3.51cto.com/wyfs02/M02/70/F0/wKioL1XBsw3TAfbuAAMlV53n9Sg228.jpg" alt="wKioL1XBsw3TAfbuAAMlV53n9Sg228.jpg" />
為此,仔細查看了eclipse-jee-luna-SR2-win32的readme_eclipse.html文檔(位於安裝路徑下的readme檔案夾中)。在文檔的第4部分“Running Eclipse”中的“Allocating enough memory and solving OutOfMemoryErrors”部分給出了這個問題的答案:
By default, Eclipse will allocate up to 512 megabytes of Java heap memory. This should be ample for all typical development tasks. However, depending on the JRE that you are running, the number of additional plug-ins you are using, and the number of files you will be working with, you could conceivably have to increase this amount. Eclipse allows you to pass arguments directly to the Java VM using the -vmargs command line argument, which must follow all other Eclipse specific arguments. Thus, to increase the available heap memory, you would typically use:
eclipse -vmargs -Xmx<memory size>
with the <memory size> value set to greater than "512M" (512 megabytes -- the default).
When using an Oracle VM below 1.8, you may also need to increase the size of the permanent generation memory. The default maximum is 64 megabytes, but more may be needed depending on your plug-in configuration and use. When the VM runs out of permanent generation memory, it may crash or hang during class loading. This failure is less common when using Oracle JRE version 1.5.0_07 or greater. The maximum permanent generation size is increased using the -XX:MaxPermSize=<memory size> argument:
eclipse -vmargs -XX:MaxPermSize=<memory size>
This argument may not be available for all VM versions and platforms; consult your VM documentation for more details.
Note that setting memory sizes to be larger than the amount of available physical memory on your machine will cause Java to "thrash" as it copies objects back and forth to virtual memory, which will severely degrade your performance.
受此啟發,這次沒再進入Eclipse環境去通過設定喜好設定來設定JVM的記憶體,而是建立了一個eclipse的捷徑,在捷徑中將預設的D:\eclipse-jee-luna-SR2-win32\eclipse.exe修改為D:\eclipse-jee-luna-SR2-win32\eclipse.exe -vmargs -Xmx1024M。並將開發環境中之前嘗試過程中設定的JVM參數清空。
再次嘗試,成功!
本文出自 “木頭” 部落格,請務必保留此出處http://highforest.blog.51cto.com/125539/1681844
Eclipse java.lang.OutOfMemoryError: Java heap space故障處理過程