I am trying to find memory leaks in one of our plugins and wanted to ask for best strategies.
When calling the plugin in a loop over and over again, RAM was used until it is out of memory.
I was able to free resources by calling
dispose() on some objects. I read that in Java it is generally not necessary to destroy objects, but for example
DatasetView has a
dispose() function that needs to be called at the end I think.
RAM usage is better now, but calling the plugin in a loop still throws a
java.lang.OutOfMemoryError: GC overhead limit exceeded after a while. Running
System.gc() after each plugin call did not help.
I read the section about Debugging Memory Leaks in the Wiki, here are two screenshots, not sure where to go from here.
This looks to me like threads get accumulated and cause the issue - but I am new to this so I’m not sure. The plugin creates threads in this fashion:
ExecutorService pool = Executors.newSingleThreadExecutor(); pool.submit(..) pool.shutdown();
Multiple topics, sorry… These are my general questions:
- What is the best way to tell if a plugin is leaking memory? Can I do this with a JUnit test or something?
- How do I know which classes have special dispose functions, especially in ImageJ / imglib2?
- How to dispose ExecutorService threads correctly / could this be a cause for
GC overhead limit exceeded?