Question

How can the memory leak in Eclipse RCP applications detected?

Was it helpful?

Solution

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.

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.

alt text
(source: oracle.com)

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

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.

OTHER TIPS

You need some kind of profiling tool.

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

Also, it looks like TPTP also does profiling.

The simplest solution comes with Java JDK: Java VisualVM.

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

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

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

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

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?).

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.

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.

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/

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top