Eclipse RCP应用程序中的内存泄漏

时间:2023-01-12 12:11:03

How can the memory leak in Eclipse RCP applications detected?

如何检测Eclipse RCP应用程序中的内存泄漏?

5 个解决方案

#1


You might want try the Memory Leak Detector that comes with JRockit Mission Control together with Eclipse MAT. It's a powerful combination. Both tools are free to use for development.

您可能需要尝试使用JRockit Mission Control附带的Memory Leak Detector和Eclipse MAT。这是一个强大的组合。这两种工具都可以免费用于开发。

With JRockit Mission Control you can inspect the heap online and see the exact number objects of a certain type that are live, without the need to take time consuming snapshots. You can directly see if you got an an Editor, View or listener object left on the heap after you closed the View/Editor. It's usually a framework listener that holds on to your view/editor. Remember, you must go to Windows->Preferences->Memory Leak Detector->Trend and set Lowest Heap Usage to report to 0.0 to se all object instances.

使用JRockit Mission Control,您可以在线检查堆并查看实时特定类型的确切数量对象,而无需花费时间来拍摄快照。关闭视图/编辑器后,您可以直接查看堆上是否有编辑器,视图或侦听器对象。它通常是一个框架监听器,可以保存您的视图/编辑器。请记住,您必须转到Windows-> Preferences-> Memory Leak Detector-> Trend并将最低堆使用率设置为0.0以报告所有对象实例。

alt text http://download.oracle.com/docs/cd/E11035_01/jrockit/intro/wwimages/memleak2.gif

替代文字http://download.oracle.com/docs/cd/E11035_01/jrockit/intro/wwimages/memleak2.gif

With MAT you can then use the shortest path to thread root to find the chain that is holding on to the leaking object. See below

使用MAT,您可以使用最短路径来查找根目录,以找到保留泄漏对象的链。见下文

alt text http://dev.eclipse.org/blogs/memoryanalyzer/files/2008/04/path2gc_all.png

alt text http://dev.eclipse.org/blogs/memoryanalyzer/files/2008/04/path2gc_all.png

Modify your code and verify with the Memory Leak Detector that the object is garbage collected when you close the editor/view.

修改代码并使用内存泄漏检测程序验证在关闭编辑器/视图时对象是垃圾回收。

#2


You need some kind of profiling tool.

您需要某种分析工具。

There is a Memory Analyzer project at eclipse (wiki, blog).

eclipse(维基,博客)上有一个Memory Analyzer项目。

Also, it looks like TPTP also does profiling.

此外,它看起来像TPTP也进行分析。

#3


The simplest solution comes with Java JDK: Java VisualVM.

最简单的解决方案是Java JDK:Java VisualVM。

It's located in the bin directory (jvisualvm.exe under Windows) since JDK 6 update 7.

自JDK 6更新7以来,它位于bin目录(Windows下的jvisualvm.exe)中。

Also includes a memory profiler, a heap walker and an Eclipse integration.

还包括内存分析器,堆walker和Eclipse集成。

https://visualvm.dev.java.net/images/getstarted/vvm-anagram-profiler.png (too bad, I'm not allowed to use image tags)

https://visualvm.dev.java.net/images/getstarted/vvm-anagram-profiler.png(太差了,我不允许使用图片标签)

See https://visualvm.dev.java.net/

#4


If you're on windows the simplest way is simply to monitor the e.g. eclipse.exe process in Task Manager while using the tool. If your RCP executable has a different name then this is what you'll need to monitor. On Unix you can use an analogous tool (proc maybe?).

如果你在Windows上,最简单的方法就是监控例如使用该工具时,任务管理器中的eclipse.exe进程。如果您的RCP可执行文件具有不同的名称,那么这就是您需要监视的内容。在Unix上,你可以使用类似的工具(proc也许?)。

Perform the most intensive tasks available (or if you suspect certain functions cause the problem, use those). IF the amount of memory used by eclipse.exe rises does not eventually decrease after your intensive tasks have completed then you likely have a leak. This will eventually cause an out of memory error.

执行可用的最密集的任务(或者如果您怀疑某些功能导致问题,请使用它们)。如果eclipse.exe使用的内存量在密集型任务完成后最终没有减少,那么您可能会发生泄漏。这最终会导致内存不足错误。

You can accelerate an out of memory error by reducing the amount of memory available to the application via the "-Xmx" setting in eclipse.ini (or .ini). E.g. -Xmx256m means a maximum 256 megabytes is available. Obviously this setting still needs to be sufficient to run your app, but a lower setting will force more frequent garbage collection and make leaks more apparent.

您可以通过eclipse.ini(或.ini)中的“-Xmx”设置减少应用程序可用的内存量来加速内存不足错误。例如。 -Xmx256m表示最大可用256兆字节。显然,此设置仍然需要足以运行您的应用程序,但较低的设置将强制更频繁的垃圾收集并使泄漏更明显。

#5


You need a memory profiler (as others have mentioned.) Once you have a good tool, you can find the problems rather easily.

你需要一个内存分析器(正如其他人提到的那样)。一旦你拥有了一个好的工具,你就可以很容易地找到问题。

We use: http://www.yourkit.com/

我们使用:http://www.yourkit.com/

for our testing, it works very well, has floating licenses so devs can use it locally on their machines.

对于我们的测试,它运行良好,具有浮动许可证,因此开发人员可以在他们的机器上本地使用它。

Basically, you take a snapshot of the actions that you are taking and then look at the items that were allocated and not released.

基本上,您可以拍摄正在执行的操作的快照,然后查看已分配但未释放的项目。

Edit: I forgot to add, this tool integrates right into eclipse.

编辑:我忘了添加,这个工具集成到eclipse中。

#1


You might want try the Memory Leak Detector that comes with JRockit Mission Control together with Eclipse MAT. It's a powerful combination. Both tools are free to use for development.

您可能需要尝试使用JRockit Mission Control附带的Memory Leak Detector和Eclipse MAT。这是一个强大的组合。这两种工具都可以免费用于开发。

With JRockit Mission Control you can inspect the heap online and see the exact number objects of a certain type that are live, without the need to take time consuming snapshots. You can directly see if you got an an Editor, View or listener object left on the heap after you closed the View/Editor. It's usually a framework listener that holds on to your view/editor. Remember, you must go to Windows->Preferences->Memory Leak Detector->Trend and set Lowest Heap Usage to report to 0.0 to se all object instances.

使用JRockit Mission Control,您可以在线检查堆并查看实时特定类型的确切数量对象,而无需花费时间来拍摄快照。关闭视图/编辑器后,您可以直接查看堆上是否有编辑器,视图或侦听器对象。它通常是一个框架监听器,可以保存您的视图/编辑器。请记住,您必须转到Windows-> Preferences-> Memory Leak Detector-> Trend并将最低堆使用率设置为0.0以报告所有对象实例。

alt text http://download.oracle.com/docs/cd/E11035_01/jrockit/intro/wwimages/memleak2.gif

替代文字http://download.oracle.com/docs/cd/E11035_01/jrockit/intro/wwimages/memleak2.gif

With MAT you can then use the shortest path to thread root to find the chain that is holding on to the leaking object. See below

使用MAT,您可以使用最短路径来查找根目录,以找到保留泄漏对象的链。见下文

alt text http://dev.eclipse.org/blogs/memoryanalyzer/files/2008/04/path2gc_all.png

alt text http://dev.eclipse.org/blogs/memoryanalyzer/files/2008/04/path2gc_all.png

Modify your code and verify with the Memory Leak Detector that the object is garbage collected when you close the editor/view.

修改代码并使用内存泄漏检测程序验证在关闭编辑器/视图时对象是垃圾回收。

#2


You need some kind of profiling tool.

您需要某种分析工具。

There is a Memory Analyzer project at eclipse (wiki, blog).

eclipse(维基,博客)上有一个Memory Analyzer项目。

Also, it looks like TPTP also does profiling.

此外,它看起来像TPTP也进行分析。

#3


The simplest solution comes with Java JDK: Java VisualVM.

最简单的解决方案是Java JDK:Java VisualVM。

It's located in the bin directory (jvisualvm.exe under Windows) since JDK 6 update 7.

自JDK 6更新7以来,它位于bin目录(Windows下的jvisualvm.exe)中。

Also includes a memory profiler, a heap walker and an Eclipse integration.

还包括内存分析器,堆walker和Eclipse集成。

https://visualvm.dev.java.net/images/getstarted/vvm-anagram-profiler.png (too bad, I'm not allowed to use image tags)

https://visualvm.dev.java.net/images/getstarted/vvm-anagram-profiler.png(太差了,我不允许使用图片标签)

See https://visualvm.dev.java.net/

#4


If you're on windows the simplest way is simply to monitor the e.g. eclipse.exe process in Task Manager while using the tool. If your RCP executable has a different name then this is what you'll need to monitor. On Unix you can use an analogous tool (proc maybe?).

如果你在Windows上,最简单的方法就是监控例如使用该工具时,任务管理器中的eclipse.exe进程。如果您的RCP可执行文件具有不同的名称,那么这就是您需要监视的内容。在Unix上,你可以使用类似的工具(proc也许?)。

Perform the most intensive tasks available (or if you suspect certain functions cause the problem, use those). IF the amount of memory used by eclipse.exe rises does not eventually decrease after your intensive tasks have completed then you likely have a leak. This will eventually cause an out of memory error.

执行可用的最密集的任务(或者如果您怀疑某些功能导致问题,请使用它们)。如果eclipse.exe使用的内存量在密集型任务完成后最终没有减少,那么您可能会发生泄漏。这最终会导致内存不足错误。

You can accelerate an out of memory error by reducing the amount of memory available to the application via the "-Xmx" setting in eclipse.ini (or .ini). E.g. -Xmx256m means a maximum 256 megabytes is available. Obviously this setting still needs to be sufficient to run your app, but a lower setting will force more frequent garbage collection and make leaks more apparent.

您可以通过eclipse.ini(或.ini)中的“-Xmx”设置减少应用程序可用的内存量来加速内存不足错误。例如。 -Xmx256m表示最大可用256兆字节。显然,此设置仍然需要足以运行您的应用程序,但较低的设置将强制更频繁的垃圾收集并使泄漏更明显。

#5


You need a memory profiler (as others have mentioned.) Once you have a good tool, you can find the problems rather easily.

你需要一个内存分析器(正如其他人提到的那样)。一旦你拥有了一个好的工具,你就可以很容易地找到问题。

We use: http://www.yourkit.com/

我们使用:http://www.yourkit.com/

for our testing, it works very well, has floating licenses so devs can use it locally on their machines.

对于我们的测试,它运行良好,具有浮动许可证,因此开发人员可以在他们的机器上本地使用它。

Basically, you take a snapshot of the actions that you are taking and then look at the items that were allocated and not released.

基本上,您可以拍摄正在执行的操作的快照,然后查看已分配但未释放的项目。

Edit: I forgot to add, this tool integrates right into eclipse.

编辑:我忘了添加,这个工具集成到eclipse中。