Re: Memory leak

Posted by Wayne Rasband on
URL: http://imagej.273.s1.nabble.com/Memory-leak-tp3700430p3700431.html

> I have written a plugin that causes a memory leak.  Each time I run
> the plugin on a single image (3600 kB TIF) the memory monitor shows
> about 14 MB of memory is not released.
>
> The plugin does a variety of operations:
> Polynomial Fit (by Bob Dougherty)
> Image Calculator
> Multiply
> Bandpass Filter
> Threshold
> Analyze Particles
>
> At this stage I can't tell where the memory is being retained.  I'm
> wondering if there is a general rule for ImageJ plugin development to
> avoid this problem.  If I was just looking at single images it
> wouldn't be a concern, but I want to process sets of images (e.g.
> 100s) and I can run out of available memory.

You can monitor memory usage by starting the Memory Monitor
(Plugins>Utilities>Monitor Memory) and then running the plugin. While
it is running, periodically click in the ImageJ status bar to force the
Java garbage collector to run. Try adding two or three second delays
[IJ.wait(2000)] between operations to help determine which one is
retaining the memory.

-wayne