本文介绍了java.lang.OutOfMemoryError:PermGen space:java reflection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码中使用java反射:

I use java reflection in the code like this:

Method method = LogFactory.class.getDeclaredMethod("getContextClassLoader");
method.setAccessible(true);
ClassLoader classLoader = (ClassLoader)method.invoke(null);
LogFactory.release(classLoader);

我用 jprofiler 可以看到很多类似的这个 sun.reflect.GeneratedMethodAccessor11

I use jprofiler can see many class like this sun.reflect.GeneratedMethodAccessor11

这些课程每次通话都会增加

these classes are increased per call

sun.reflect.BootstrapConstructorAccessorImpl
sun.reflect.NativeConstructorAccessorImpl
sun.reflect.DelegatingConstructorAccessorImpl
sun.reflect.DelegatingClassLoader

我认为这就是为什么PermGen空间增加,如何清理这些类?

I think this is why PermGen space increase, how to clean these classes?

推荐答案

有一篇非常好的文章讨论。

There is a pretty nice article discussing about potential native memory use in reflection delegating classloaders.

设置 sun .reflect.inflationThreshold 到0 -Dsun.reflect.inflationThreshold = 0 会为你做一些技巧。

Set sun.reflect.inflationThreshold to 0 by -Dsun.reflect.inflationThreshold=0 will do the tricks for you.

这篇关于java.lang.OutOfMemoryError:PermGen space:java reflection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-09 05:18