out of memory: multiple images

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

out of memory: multiple images

Martin du Saire
Hi,

I am running a macro containing a bunch of user-defined functions in
BatchMode on a entire directory of 35kb images.  The macro makes it
through about 160 images before ImageJ reports "out of memory".  I am
sure I am closing all the intermediate and the resulting images in
each loop, and the only output other than the resulting image, is a
couple lines in "Log" per image.  Any ideas?  Does ImageJ create new
versions of variable, arrays etc. each time the process is run?

For example, does "x0=newArray(nBlobs);" create a separate array each
time it is called, or does it overwrite x0?

Thanks.

M
Reply | Threaded
Open this post in threaded view
|

Re: out of memory: multiple images

Volker Baecker
Hi,
x0=newArray(nBlobs); will use new memory, however if there's no other
reference to the "old content" of x0, the memory containing the old
content will be given back by the garbage collector.
And this might be the problem. If you have a tight loop the garbage
collector may never be able to run. Try to force a garbage collection at
the beginning of the loop using IJ.freeMemory(). You can print the
string you get back from the method to see what happens to the memory.
Cheers,
Volker


Martin du Saire a écrit :

> Hi,
>
> I am running a macro containing a bunch of user-defined functions in
> BatchMode on a entire directory of 35kb images.  The macro makes it
> through about 160 images before ImageJ reports "out of memory".  I am
> sure I am closing all the intermediate and the resulting images in
> each loop, and the only output other than the resulting image, is a
> couple lines in "Log" per image.  Any ideas?  Does ImageJ create new
> versions of variable, arrays etc. each time the process is run?
>
> For example, does "x0=newArray(nBlobs);" create a separate array each
> time it is called, or does it overwrite x0?
>
> Thanks.
>
> M
>

--
passerelle antivirus du campus CNRS de Montpellier
--
Reply | Threaded
Open this post in threaded view
|

Antwort: Re: out of memory: multiple images

Joachim Wesner
>And this might be the problem. If you have a tight loop the garbage
>collector may never be able to run. Try to force a garbage collection at
>the beginning of the loop using IJ.freeMemory().

Really? I would say then it is a silly implementation! I the app runs out
of memory,
the first thing the JVM should try is to call the garbage collector
to see if it can get some memory back before it throws an exception.
I thought, trying to run the GC earlier only makes sense to avoid any
delays to happen
when you do not want be interrupted if possible at all!


JW


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

Re: out of memory: multiple images

Martin du Saire
In reply to this post by Volker Baecker
Uh, I think the problem has been resolved.  I inserted:

        print("Free memory:", call("ij.IJ.freeMemory")); // returns a string

at the beginning of the loop.  It reported that
1% of the 300Mb was free.  This is reported at
the beginning of the macro, prior to opening any
images!  Is that the expected result?  Anyway, I
ran through a directory with 180 (34kb on disk)
images with no problem.  So, then I commented out
the line, and ran the macro again: No problem.  Go figure...

If ImageJ tries to grab the 300mb for itself a
the outset, could come into conflict with higher
priority processes at some point, and thus report that it is out of memory?

For the record:  ImageJ1.37h Java1.0.5 on XP

Thanks.

Martin

At 02:44 AM 7/3/2006, you wrote:

>Hi,
>x0=newArray(nBlobs); will use new memory,
>however if there's no other reference to the
>"old content" of x0, the memory containing the
>old content will be given back by the garbage collector.
>And this might be the problem. If you have a
>tight loop the garbage collector may never be
>able to run. Try to force a garbage collection
>at the beginning of the loop using
>IJ.freeMemory(). You can print the string you
>get back from the method to see what happens to the memory.
>Cheers,
>Volker
>
>
>Martin du Saire a écrit :
>>Hi,
>>
>>I am running a macro containing a bunch of
>>user-defined functions in BatchMode on a entire
>>directory of 35kb images.  The macro makes it
>>through about 160 images before ImageJ reports
>>"out of memory".  I am sure I am closing all
>>the intermediate and the resulting images in
>>each loop, and the only output other than the
>>resulting image, is a couple lines in "Log" per
>>image.  Any ideas?  Does ImageJ create new
>>versions of variable, arrays etc. each time the process is run?
>>
>>For example, does "x0=newArray(nBlobs);" create
>>a separate array each time it is called, or does it overwrite x0?
>>
>>Thanks.
>>
>>M
>
>--
>passerelle antivirus du campus CNRS de Montpellier
>--
Reply | Threaded
Open this post in threaded view
|

Re: out of memory: multiple images

Wayne Rasband
In reply to this post by Martin du Saire
On Jul 3, 2006, at 10:41 AM, Martin du Saire wrote:


> Uh, I think the problem has been resolved.  I inserted:
>
>        print("Free memory:", call("ij.IJ.freeMemory")); // returns  
> a string
>
> at the beginning of the loop.  It reported that 1% of the 300Mb was  
> free.  This is reported at the beginning of the macro, prior to  
> opening any images!  Is that the expected result?
>

This is what I get on my system:

      Free memory: 1110K of 500MB (<1%)

This means that 1110K of the available 500MB of memory (or less than  
1%) is in use. In other words, more than 99% is free. This string is  
also displayed by the Help>About ImageJ command and when you click in  
the status bar.

-wayne