Java heap space或者permgen space的的解決方法


一、因為程序要從數據讀取近10W行記錄處理,當讀到9W的時候就出現 java.lang.OutOfMemoryError: Java heap space 這樣的錯誤。
在網上一查可能是JAVA的堆棧設置太小的原因,結合網上的答案大致解決方法為:

報錯如下:
Exception in thread "DispatcherThread" java.lang.OutOfMemoryError: PermGen space Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" java.lang.OutOfMemoryError: PermGen space Exception in thread "State Saver" java.lang.OutOfMemoryError: PermGen space Exception in thread "AWT-Windows" java.lang.OutOfMemoryError: OutOfMemoryError
產生原因:
PermGen space的全稱是Permanent Generation space,是指內存的永久保存區域,這塊內存主要是被JVM存放Class和Meta信息的,
Class在被Loader時就會被放到PermGen space中,它和存放類實例(Instance)的Heap區域不同,GC(Garbage Collection)不會在主程序
運行期對PermGen space進行清理,所以如果你的應用中有很多CLASS的話,就很可能出現PermGen space錯誤,這種錯誤常見在web服務器對JSP進行pre compile的時候。
如果你的WEB APP下都用了大量的第三方jar, 其大小超過了jvm默認的大小(4M)那么就會產生此錯誤信息了。

   解決方法如下:

run→run configurations→vmarguments:添加

-Xmx1024M -Xms512M -XX:MaxPermSize=512m

二、

提示信息:

Error occurred during initialization of VM
Could not reserve enough space for object heap

修改配置文件:

eclipse.ini

 

-startup
plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1.1.300.v20150602-1417
-product
org.eclipse.epp.package.jee.product
--launcher.defaultAction
openFile
--launcher.XXMaxPermSize
256M
-showsplash
org.eclipse.platform
--launcher.XXMaxPermSize
256m
--launcher.defaultAction
openFile
--launcher.appendVmargs
-vmargs
-Dosgi.requiredJavaVersion=1.7
-Xms256m
-Xmx512m

解決方法:將最后一行改為-Xmx1024m。保存后再次啟動eclipse,就OK了。

 

 

三、eclipse一直報An internal error occurred during: "Building workspace". GC overhead limit exceeded

 

最近導入到eclipse里的工程挺大的,每次eclipse啟動之后都回update workspace,然后就一直報:

 

An internal error occurred during: "Building workspace". GC overhead limit exceeded

 

這個錯誤。

解決方法: 

原因是Eclipse默認配置內存太小需要更改Eclipse安裝文件夾下的eclipse.ini文件。

Eclipse.ini默認文件如下:

修改如下:

-Xms512m -Xmx1024m

第一個是最小的初始化內存,第二個是最大的占有內存

還可以加上 -XX:MaxPermSize=1024m這個意思是在編譯文件時一直占有最大內存,重啟Eclipse

 

如果你的電腦內存足夠大,就多分配一點個eclipse吧。我都設置成512m還是會報錯,干脆都給設置成1024了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM