Login  Register

Re: Is ImageJ memory-leaky?

Posted by Albert Cardona on Sep 14, 2005; 12:49pm
URL: http://imagej.273.s1.nabble.com/Is-ImageJ-memory-leaky-tp3704878p3704883.html

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