线程“main”中的异常 java.lang.OutOfMemoryError: Java heap space
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2381849/
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
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
提问by Johanna
I have written a code and I run it a lot but suddenly I got an OutOfMemoryError
:
我写了一个代码,我运行了很多,但突然我得到了一个OutOfMemoryError
:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at javax.media.j3d.BoundingBox.<init>(BoundingBox.java:86)
at javax.media.j3d.NodeRetained.<init>(NodeRetained.java:198)
at javax.media.j3d.LeafRetained.<init>(LeafRetained.java:40)
at javax.media.j3d.LightRetained.<init>(LightRetained.java:44)
at javax.media.j3d.DirectionalLightRetained.<init>(DirectionalLightRetained.java:50)
at javax.media.j3d.DirectionalLight.createRetained(DirectionalLight.java:116)
at javax.media.j3d.SceneGraphObject.<init>(SceneGraphObject.java:119)
at javax.media.j3d.Node.<init>(Node.java:178)
at javax.media.j3d.Leaf.<init>(Leaf.java:50)
at javax.media.j3d.Light.<init>(Light.java:270)
at javax.media.j3d.DirectionalLight.<init>(DirectionalLight.java:87)
回答by Jon Skeet
Well, it's fairly self-explanatory: you've run out of memory.
嗯,这是不言自明的:您的内存不足。
You may want to try starting it with more memory, using the -Xmx flag, e.g.
您可能想尝试使用 -Xmx 标志以更多内存启动它,例如
java -Xmx2048m [whatever you'd have written before]
This will use up to 2 gigs of memory.
这将使用多达 2 演出的内存。
See the non-standard options listfor more details.
有关更多详细信息,请参阅非标准选项列表。
回答by Keith Randall
You're out of memory. Try adding -Xmx256m
to your java command line. The 256m
is the amount of memory to give to the JVM (256 megabytes). It usually defaults to 64m
.
你的内存不足。尝试添加-Xmx256m
到您的 java 命令行。这256m
是分配给 JVM 的内存量(256 兆字节)。它通常默认为64m
.
回答by Enno Shioji
I don't know about javax.media.j3d, so I might be mistaken, but you usually want to investigate whether there is a memory leak. Well, as others note, if it was 64MB and you are doing something with 3d, maybe it's obviously too small...
我不知道javax.media.j3d,所以我可能会误会,但你通常想调查是否存在内存泄漏。好吧,正如其他人所指出的,如果它是 64MB 而你正在用 3d 做一些事情,也许它显然太小了......
But if I were you, I'll set up a profiler or visualvm, and let your application run for extended time (days, weeks...). Then look at the heap allocation history, and make sure it's not a memory leak.
但是如果我是你,我会设置一个分析器或visualvm,让你的应用程序运行更长的时间(几天、几周......)。然后查看堆分配历史,并确保它不是内存泄漏。
If you use a profiler, like JProfiler or the one that comes with NetBeans IDE etc., you can see what object is being accumulating, and then track down what's going on.. Well, almost always something is incorrectly not removed from a collection...
如果您使用探查器,如 JProfiler 或 NetBeans IDE 附带的探查器等,您可以查看正在累积的对象,然后跟踪正在发生的事情……嗯,几乎总是有一些东西没有从集合中被错误地删除。 ..
回答by borchvm
-Xmx1024m -XX:MaxPermSize=512m -Xms512m
-Xmx1024m -XX:MaxPermSize=512m -Xms512m
Add this parameter as argument in your server params
将此参数添加为服务器参数中的参数
回答by Kaleem Ullah
If you're recompiling a disassembled APK
with APK tool:
如果你正在重新编译一个反汇编APK
的 APK 工具:
Just Set Memory Allocation a little bigger
只需将内存分配设置大一点
set switch -Xmx1024m
to -Xmx2048m
将开关设置-Xmx1024m
为-Xmx2048m
java -Xmx2048m -jar signapk.jar -w testkey.x509.pem testkey.pk8 "%APKOUT%" "%SIGNED%"
you're good to go.. :)
你很高兴.. :)