如何避免 java.lang.OutOfMemoryError: Netbeans 中的 PermGen 空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3521819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to avoid java.lang.OutOfMemoryError: PermGen space in Netbeans
提问by Rohan Bomle
I am developing on Web Application in Netbeans6.8 and Using Jboss server to Deploy my application. I am able to run the project properly but after some time i get tgis error
我正在 Netbeans6.8 中开发 Web 应用程序并使用 Jboss 服务器部署我的应用程序。我能够正确运行该项目,但一段时间后出现 tgis 错误
java.lang.OutOfMemoryError: PermGen space :
after that i have to restart my JBoss server. Some time i need to restart my Netbeans IDE Can any one tell me the reason of this error and How to avoid this
之后我必须重新启动我的 JBoss 服务器。有一段时间我需要重新启动我的 Netbeans IDE 谁能告诉我这个错误的原因以及如何避免这种情况
Thanks Rohan
谢谢罗汉
回答by Jigar Joshi
add this
添加这个
-XX:+UseConcMarkSweepGC
-XX:+CMSPermGenSweepingEnabled
-XX:+CMSClassUnloadingEnabled
-XX:MaxPermSize=128m
回答by ksm
adding more megs to your heap will not solve your problem, you could add infinity & still run out cuz of sloppy code. more than the issue of JBoss, i suppose that your code most probably has memory leaks in it, since it runs out of heap 'after some time'. its a typical scenario. i suggest that you profile your code using JVisualVM (built-in into SUN JDK6 etc)... have a look at the heap & see what object are have the most instances, total size wise. once you fix those code issue, i dont think you'd want to add more space to your heap.
向您的堆添加更多 meg 不会解决您的问题,您可以添加无穷大,但仍然会用完草率的代码。不仅仅是 JBoss 的问题,我想你的代码很可能有内存泄漏,因为它在“一段时间后”用完堆。这是一个典型的场景。我建议您使用 JVisualVM(内置于 SUN JDK6 等中)分析您的代码......查看堆并查看哪些对象拥有最多的实例,总大小明智。一旦您修复了这些代码问题,我认为您不会想要为堆添加更多空间。
rgds -ksm
rgds -ksm
回答by Bivas
add -XXMaxPermSize=256Mto your application start-up command
添加-XXMaxPermSize=256M到您的应用程序启动命令
回答by duffymo
Bounce your server from time to time. You might not like this limit on your ability to hot deploy, but the problem is that eventually you'll hit the perm gen ceiling again when you redeploy too many times.
不时退回您的服务器。您可能不喜欢这种热部署能力的限制,但问题是,当您重新部署太多次时,最终会再次达到永久上限。
Just bounce the server every nth redeploy, where n < # that causes OOM error.
每隔 n 次重新部署就反弹服务器,其中 n < # 会导致 OOM 错误。
回答by Zaki Khan
Use this command in your VM:-
在您的 VM 中使用此命令:-
Increase the heap size as such:
像这样增加堆大小:
-Xms256m -Xmx512m -XX:PermSize=64M -XX:MaxPermSize=1000M
-Xms256m -Xmx512m -XX:PermSize=64M -XX:MaxPermSize=1000M
These values should be provided to the VM.
这些值应提供给 VM。
after that restart server.
之后重启服务器。

