I´m trying to use ratio Plus plugin to generate a stack calculating
ratio between two stacks. My problem is that I use several hundreds of images and ImageJ is out of memory too easily (I have allocated 450 Mb f RAM). I say "too easily" because the same original stacks can generate a third stack of images in Metafluor Analyst withou memory problems, so that increasing amount of RAM is not the best solution Thanks |
Pedro,
ImageJ is not leaky that I know of, at all. Memory issues have to do with how the java virtual machine works. This is not so different from C/C++: memory has to be released at some point or your virtual machine will run out of RAM space before it occurs to it to run a garbage collector. So I recommend you insert code into your plugin that: 1) checks how much memory is available 2) if not enough for what you want to do, release it by calling in a while(true) loop the garbage collector until enough memory has been released. 3) proceed with whatever memory-consuming task ImageJ has in the ij.IJ class methods to tests the amount of available memory; if you want to do it manually check the java.lang.System class If this does not address your problem because your plugin actually uses all that filled-up memory, try dynamic loading/unloading of memory: release what you don't need at the moment and then reload it when it is needed. This way I manage to deal with 6 GB of images at the same time in a 512Mb RAM machine. Albert -- Albert Cardona Institute of Neuroinformatics Tel : +41 1 635 3052 University/ETH Zurich Fax : +41 1 635 3053 Winterthurerstrasse 190 acardona (at) ini phys ethz ch Zurich 8057, Switzerland www.ini.unizh.ch |
On Wednesday 14 September 2005 10:24, Albert Cardona wrote:
> So I recommend you insert code into your plugin that: > 2) if not enough for what you want to do, release it by calling in a > while(true) loop the garbage collector until enough memory has been > released. What is the code to do this? Many thanks, G. |
In reply to this post by Pedro J CamelloDr Pedro J Camello
Mr. G,
The code to release memory is a simple call to the garbage collector. You can run a test for 10 iterations (a while(true) loop is rather dangerous unless carefully planned) : //define the minimum ammount of free memory you need: int min_free_memory = 50; //in percentage of total int i =0; for (; i<10; i++) { // run garbage collector: System.gc(); // check for free memory: int free_memory = 100 - (IJ.currentMemory() * 100 / IJ.maxMemory()); if (free_memory >= min_free_memory) { break; } } if (10 == i) { IJ.log("Failed to release enough memory."); } Albert Cardona Institute of Neuroinformatics Tel : +41 1 635 3052 University/ETH Zurich Fax : +41 1 635 3053 Winterthurerstrasse 190 acardona (at) ini phys ethz ch Zurich 8057, Switzerland www.ini.unizh.ch |
On Wednesday 14 September 2005 12:49, Albert Cardona wrote:
> The code to release memory is a simple call to the garbage collector. You > can run a test for 10 iterations (a while(true) loop is rather dangerous > unless carefully planned) : Many thanks, this is very useful. Cheers, Gabriel |
In reply to this post by Albert Cardona
Many thanks, Albert
regarding your last paragraph _/If this does not address your problem because your plugin actually uses all that filled-up memory, try dynamic loading/unloading of memory: release what you don't need at the moment and then reload it when it is needed. This way I manage to deal with 6 GB of images at the same time in a 512Mb RAM machine. /_ could you please explain how to do it /grosso modo? /(I´m afraid in the next months I´ll need to handle big stacks) Albert Cardona wrote: >Pedro, > >ImageJ is not leaky that I know of, at all. Memory issues have to do with how >the java virtual machine works. This is not so different from C/C++: memory >has to be released at some point or your virtual machine will run out of RAM >space before it occurs to it to run a garbage collector. > >So I recommend you insert code into your plugin that: > >1) checks how much memory is available >2) if not enough for what you want to do, release it by calling in a >while(true) loop the garbage collector until enough memory has been released. >3) proceed with whatever memory-consuming task > >ImageJ has in the ij.IJ class methods to tests the amount of available memory; >if you want to do it manually check the java.lang.System class > >If this does not address your problem because your plugin actually uses all >that filled-up memory, try dynamic loading/unloading of memory: release what >you don't need at the moment and then reload it when it is needed. This way I >manage to deal with 6 GB of images at the same time in a 512Mb RAM machine. > > >Albert > > |
In reply to this post by Pedro J CamelloDr Pedro J Camello
Pedro,
There are many ways to dynamically load/unload RAM memory, in this case images. A very nice and straightforward example is found in the Virtual_Stack_Opener.java plugin by Wayne, at http://rsb.info.nih.gov/ij/plugins/virtual-opener.html The way I do it for my purposes is to wrap the object to be loaded/unloaded in a wrapper class to which all calls to that object are piped. So when the object is required, the wrapper class first makes some space by telling the cache to do so, loads it either from scratch (as the files in the Virtual Stack Opener) or from the cache, and then sends it to the cache for storing. The cache keeps a first-in-first-out queue of the objects and self-regulates itself to make space, releasing as many of the least-used objects first (the older ones in the queue) as needed. Hope it helps. Albert -- Albert Cardona Institute of Neuroinformatics Tel : +41 1 635 3052 University/ETH Zurich Fax : +41 1 635 3053 Winterthurerstrasse 190 acardona (at) ini phys ethz ch Zurich 8057, Switzerland www.ini.unizh.ch |
Free forum by Nabble | Edit this page |