如何防止 Netbeans 中的 PermGen 空间错误? [英] How can I prevent PermGen space errors in Netbeans?

查看:23
本文介绍了如何防止 Netbeans 中的 PermGen 空间错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每 15-30 分钟 Netbeans 就会显示一个java.lang.OutOfMemoryError: PermGen space".根据我从 Google 了解到的情况,这似乎与一般的类加载器泄漏或内存泄漏有关.

Every 15-30 minutes Netbeans shows a "java.lang.OutOfMemoryError: PermGen space". From what I learned from Google this seems to be related to classloader leaks or memory leaks in general.

不幸的是,我发现的所有建议都与应用服务器有关,我不知道将它们调整到 Netbeans.(我什至不确定是不是同样的问题)

Unfortunately all suggestions I found were related to application servers and I have no idea to adapted them to Netbeans. (I'm not even sure it's the same problem)

我的应用程序有问题吗?我如何找到来源?

Is it a problem in my application? How can I find the source?

推荐答案

这是因为不断加载类.

Java 将类字节码和所有常量(例如字符串常量)存储在默认情况下不会被垃圾收集的永久堆中(这在大多数情况下是有意义的,因为类在应用程序的生命周期内仅加载一次).

Java stores class byte code and all the constants (e.g. 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).

在整个生命周期中经常加载类的应用程序中:

In applications that often load classes during an entire lifetime that are:

  • 热重新部署期间的网络和应用服务器;
  • IDE 在运行开发的应用程序时(每次在 Netbeans 或 Eclipse 中点击运行按钮时,它都会加载应用程序的新类);
  • 等这种行为是不正确的,因为堆最终会填满.

您需要打开永久堆垃圾收集以防止出现此错误.

You need to turn on permanent heap garbage collection to prevent this error.

我使用选项

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

(阻止我的 eclipse 3.4 抛出java.lang.OutOfMemoryError: PermGen space",所以它也应该与 netbeans 一起工作).

(stopped my eclipse 3.4 from throwing "java.lang.OutOfMemoryError: PermGen space" so it should also work with netbeans).

编辑:请注意,对于 Netbeans,您可以在以下位置设置这些选项:[Netbeans 安装]etc etbeans.conf您应该在这些选项前面加上 -J 并将它们添加到 netbeans_default_options(有关详细信息,请参阅 netbeans.conf 中的注释).

Edit: Just note that for Netbeans you set those options in: [Netbeans installation]etc etbeans.conf You should prefixe those options with -J and add them in netbeans_default_options (see comments in netbeans.conf for more informations).

这篇关于如何防止 Netbeans 中的 PermGen 空间错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆