[英]Java Swing application freezes out
We have a Java application which is kinda huge and requires too much memory, although I set the initial and maximum memory using Xm
flags, but sometimes it freezes, and we get an OutOfMemoryError
after 1-2 min (if we're lucky). 我们有一个Java应用程序,它很大,需要太多内存,尽管我使用
Xm
标志设置了初始和最大内存,但有时会冻结,并且在1-2分钟后会出现OutOfMemoryError
(如果幸运的话)。
We need to restart the application if this happens. 如果发生这种情况,我们需要重新启动应用程序。
We run the program by a native c application which simply runs a command line. 我们通过仅运行命令行的本机c应用程序运行该程序。
Xmx
flag? Xmx
标志怎么办? What if I don't set the Xmx flag?
如果我没有设置Xmx标志怎么办?
Then the JVM defaults to a (typically modest) size of memory for the app. 然后,JVM默认将应用程序的内存大小设置为(通常为适度)。
Does it mean unlimited memory usage?
这是否意味着无限的内存使用?
No. 没有。
How can I realize if the application is frozen in either C or Java?
我如何知道应用程序是用C还是Java冻结的?
Fix the memory leak 1 . 修复内存泄漏1 。
Note that the question I answered used 'release' as opposed to 'realize'. 请注意,我回答的问题使用的是“发布”,而不是“实现”。 After careful consideration, I feel the answer should remain exactly the same.
经过仔细考虑,我认为答案应该完全相同。 Either 'releasing (memory)' or 'realizing (there is a problem)' is not going to actually fix the problem.
“释放(内存)”或“意识到(存在问题)”都无法真正解决问题。 It is better either way to fix the actual problem (a memory leak) .
解决实际问题(内存泄漏)的任何一种方法都更好。
As an aside. 作为旁白。 I don't think the problem is in the C code, but a simple test (launch the app. from the command line) should reveal either way.
我不认为问题出在C代码中,但是一个简单的测试(从命令行启动应用程序)应该可以揭示这两种方法。 The reason I think the problem is the Java code is that the
OutOfMemoryError
is detected by a (presumably) fully functional JVM. 我认为这个问题是Java代码的原因是
OutOfMemoryError
是由(大概)全功能的JVM检测。
If the C app. 如果是C app。 had used memory space that the JVM reserved for itself or the app.
使用了JVM为其本身或应用程序保留的内存空间 。 I guess the error would be very different, possibly along the lines of:
JVM internal error..
我猜想错误可能会大不相同,可能是由于以下原因:
JVM internal error..
There has been a range of good advice offered by other contributors, that I will revisit here. 其他贡献者还提供了一系列好的建议,我将在这里重新讨论。
close()
all: close()
全部,则在代码中搜索:
Running your application using C native code does not mean that you may be able to steer the whole memory usage by the JVM parameters. 使用C本机代码运行应用程序并不意味着您可以通过JVM参数来控制整个内存的使用。 Try running a memory monitoring for your system (eg TOP on Linux with shift+m for memory usage sorting) or better yet profile your application for memory.
尝试为系统运行内存监视(例如,在Linux上使用shift + m对TOP进行内存使用排序),或者更好地为内存配置应用程序。
Try to get a memory dump after running your application (there are some profiling tools out there, most IDEs provide some feature as well) to check your java objects. 运行应用程序后尝试获取内存转储(那里有一些性能分析工具,大多数IDE也提供某些功能)来检查Java对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.