简体   繁体   English

Java反射和OOM错误

[英]Java Reflection and OOM Error

I am getting an java.lang.OutOfMemoryError and it seems to happen in a point I do reflection: 我收到一个java.lang.OutOfMemoryError ,似乎发生在我进行反思的地方:

obj.getClass().getMethod(methodName, (Class[]) null);

What does this indicate? 这说明什么? Does anyone know? 有人知道吗?

The code is the same as 代码与

obj.getClass().getMethod(methodName)

What does this indicate? 这说明什么?

It indicates you need to read the Error message carefully as this is highly unlikely to be the cause as it doesn't creates very little memory. 这表明您需要仔细阅读错误消息,因为这几乎不会成为原因,因为它不会占用很少的内存。

Does anyone know? 有人知道吗?

If it really is the point at which the error occurs, the real cause is likely to be somewhere else. 如果确实是错误发生的地点,则真正的原因可能在其他地方。 To resolve this you need to memory profile your application, or take a heap dump on OOME or increase the maximum heap size (or all three) 要解决此问题,您需要对应用程序进行内存分析,或者在OOME上进行堆转储,或者增加最大堆大小(或全部三个)

The point at which an out of memory error is thrown is often nowhere near the part of the code that's using lots of memory. 抛出内存不足错误的时间通常与使用大量内存的代码部分相去甚远。 It's thrown when the garbage collector detects a memory problem, but this can be in another thread from that which is consuming all your memory. 当垃圾收集器检测到内存问题时抛出该错误,但这可能是在消耗您所有内存的线程中的另一个线程中发生的。

If you've got no idea where the problem lies, your best bet is to run a profiler. 如果您不知道问题出在哪里,那么最好的选择是运行探查器。

I think that you have not enought PermGen space allocated. 我认为您没有足够的PermGen空间分配。 You could try -XX:PermSize=128M -XX:MaxPermSize=256M as java command line parameters for your app. 您可以尝试-XX:PermSize = 128M -XX:MaxPermSize = 256M作为应用程序的Java命令行参数。

java.lang.OutOfMemoryError is thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector. 当Java虚拟机由于内存不足而无法分配对象,并且垃圾回收器无法再提供更多内存时,将引发java.lang.OutOfMemoryError

I think it is nothing to do with obj.getClass().getMethod(methodName, (Class[]) null); 我认为这与obj.getClass().getMethod(methodName, (Class[]) null);无关obj.getClass().getMethod(methodName, (Class[]) null);

Do check why your application/program is getting out of memory. 请检查为什么您的应用程序/程序内存不足。

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

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