简体   繁体   English

如何防止Netbeans中的PermGen空间错误?

[英]How can I prevent PermGen space errors in Netbeans?

Every 15-30 minutes Netbeans shows a " java.lang.OutOfMemoryError: PermGen space ". 每隔15-30分钟,Netbeans会显示一个“ java.lang.OutOfMemoryError: PermGen space ”。 From what I learned from Google this seems to be related to classloader leaks or memory leaks in general. 从我从谷歌那里学到的东西,这似乎与一般的类加载器泄漏或内存泄漏有关。

Unfortunately all suggestions I found were related to application servers and I have no idea to adapted them to Netbeans. 不幸的是,我发现的所有建议都与应用程序服务器有关,我不知道它们是否适用于Netbeans。 (I'm not even sure it's the same problem) (我甚至不确定它是同一个问题)

Is it a problem in my application? 这是我申请中的问题吗? How can I find the source? 我怎样才能找到来源?

It is because of constant class loading. 这是因为恒定的类加载。

Java stores class byte code and all the constants (eg string constants) in permanent heap that is not garbage collected by default (which make sense in majority of situations because classes are loaded only once during the lifetime of an application). Java将类字节代码和所有常量(例如字符串常量)存储在永久堆中,默认情况下不是垃圾收集(这在大多数情况下都有意义,因为类在应用程序的生命周期中只加载一次)。

In applications that often load classes during an entire lifetime that are: 在通常在整个生命周期内加载类的应用程序中:

  • web and application servers during hot redeployment; 热重新部署期间的Web和应用程序服务器;
  • IDE's when running developed applications (every time you hit Run button in Netbeans or eclipse it loads your application's classes a new); IDE在运行已开发的应用程序时(每次在Netbeans中运行Run按钮或eclipse时,它会将应用程序的类加载为新的);
  • etc this behavior is improper because a heap fills full eventually. 等等这种行为是不恰当的,因为最终堆满了。

You need to turn on permanent heap garbage collection to prevent this error. 您需要打开永久堆垃圾收集以防止此错误。

I use options 我用的是选项

-XX:MaxPermSize=256M
-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled

(stopped my eclipse 3.4 from throwing " java.lang.OutOfMemoryError: PermGen space " so it should also work with netbeans). (阻止我的eclipse 3.4抛出“ java.lang.OutOfMemoryError: PermGen space ”,所以它也应该与netbeans一起工作)。

Edit : Just note that for Netbeans you set those options in: [Netbeans installation]\\etc\\netbeans.conf You should prefixe those options with -J and add them in netbeans_default_options (see comments in netbeans.conf for more informations). 编辑 :请注意,对于Netbeans,您可以在以下位置设置这些选项: [Netbeans installation]\\etc\\netbeans.conf您应该使用-J将这些选项作为前缀,并将它们添加到netbeans_default_options (有关更多信息,请参阅netbeans.conf注释)。

尝试将以下参数添加到netbeans netconf:-J-XX:MaxPermSize = 256m

See this link on how to set the size of PermSize. 请参阅此链接 ,了解如何设置PermSize的大小。 Most probably this isn't a problem of your code, so the only solution would be to increase the the PermSize. 最有可能这不是你的代码的问题,所以唯一的解决方案是增加PermSize。 I have found that this is quite often, when you work with JAXB. 当你使用JAXB时,我发现这很常见。 In general, if you use many libraries that themselves also depend on many other jar files, the default size of the PermGen space may not be big enough. 通常,如果您使用许多本身也依赖于许多其他jar文件的库,则PermGen空间的默认大小可能不够大。

See these blog posts for more details: Classloader leaks and How to fix the dreaded "java.lang.OutOfMemoryError: PermGen space" 有关更多详细信息,请参阅这些博客文章: 类加载器泄漏以及如何修复可怕的“java.lang.OutOfMemoryError:PermGen space”

If you are developing a web application, try to put on server vm option 如果您正在开发Web应用程序,请尝试使用服务器vm选项

-Xmx512m -Xms512m -XX:MaxPermSize=512m -Xmx512m -Xms512m -XX:MaxPermSize = 512m

Go to Tools/Servers//Platform/VM Options (Netbeans 7.4) 转到工具/服务器//平台/ VM选项(Netbeans 7.4)

You can change the startup options of netbeans JVM by editing the file /etc/netbeans.conf. 您可以通过编辑文件/etc/netbeans.conf来更改netbeans JVM的启动选项。 I often have this kind of errors when I develop a Webapp and I deploy it often. 当我开发Web应用程序并经常部署它时,我经常遇到这种错误。 In that case, I restart tomcat from time to time. 在那种情况下,我不时重启tomcat。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM