Eclipse java.lang.OutOfMemoryError: Java heap space故障處理過程

來源:互聯網
上載者:User

標籤: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故障處理過程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.