<div dir="ltr">Hi Burkhard,<div><br></div><div> > <span style="font-family:arial,sans-serif;font-size:13.333333969116211px">run("Collect Garbage");</span></div><div><span style="font-family:arial,sans-serif;font-size:13.333333969116211px"><br>
</span></div><div><span style="font-family:arial,sans-serif;font-size:13.333333969116211px"> This just calls System.gc().. twice, actually. There are many articles and StackOverflow posts about <a href="http://stackoverflow.com/questions/2414105/why-is-it-a-bad-practice-to-call-system-gc">why System.gc() is unreliable</a>. I personally have seen endlessly repeated System.gc() calls effectively do nothing, necessitating the creation of large objects to force memory to be released.</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13.333333969116211px"><br></span></div><div><span style="font-family:arial,sans-serif;font-size:13.333333969116211px"> Also, the JVM should automatically attempt to run the garbage collector when memory is requested for allocation in excess of the JVM's memory limits. So the best way to test if SCIFIO has a memory leak would be:</span></div>
<div><span style="font-family:arial,sans-serif;font-size:13.333333969116211px"><br></span></div><div><font face="arial, sans-serif">1) Open datasets that occupy slightly less than the max memory allocated to your Fiji</font></div>
<div><font face="arial, sans-serif">2) Close these datasets</font></div><div><font face="arial, sans-serif">3) Try opening more datasets (of a size such that, if the original datasets not released, the total memory used would exceed the max allocation)</font></div>
<div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">If you see OutOfMemory errors then there could quite possibly be a leak.</font></div><div><font face="arial, sans-serif"><br></font></div>
<div><font face="arial, sans-serif">Note also that we have unit tests in place designed to catch these leaks: <a href="https://github.com/scifio/scifio/blob/master/src/test/java/io/scif/img/cell/cache/utests/CacheServiceTest.java">https://github.com/scifio/scifio/blob/master/src/test/java/io/scif/img/cell/cache/utests/CacheServiceTest.java</a>. An excellent way to demonstrate the memory error would be to come up with another test in this class that fails.</font></div>
<div><font face="arial, sans-serif"><br></font></div><div><font face="arial, sans-serif">Thanks,</font></div><div><font face="arial, sans-serif">Mark</font></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Sat, Jul 12, 2014 at 1:54 PM, Burkhard Höckendorf <span dir="ltr"><<a href="mailto:burkhard.hoeckendorf@web.de" target="_blank">burkhard.hoeckendorf@web.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Dear List,<br>
<br>
First of all thanks for developing scifio and doing that open source. I have started to use it with ImageJ, since Fiji now offers the option to use it. Having said that, I may also have stumbled upon an issue. I'm unsure when (or whether) scifio releases the corresponding memory after images are closed. To look at this in a somewhat systematic way, I ran a macro (see below) to repeatedly open and close a 3GB single file uncompressed TIFF stack (2048x2048x367x16bits) and record some performance stats along the way. I ran this using a new download of Fiji.<br>
<br>
Here are the results with scifio disabled:<br>
11450 ms to open files<br>
28578184 mem before opening files<br>
<a href="tel:9282667288" value="+19282667288" target="_blank">9282667288</a> mem after opening files<br>
9272732560 mem after opening files & GC<br>
9272780080 mem after closing files<br>
24220936 mem after closing files & GC<br>
<br>
And here with scifio enabled:<br>
43715 ms to open files<br>
26765224 mem before opening files<br>
10517954400 mem after opening files<br>
9327459480 mem after opening files & GC<br>
9327506440 mem after closing files<br>
<a href="tel:9314822896" value="+19314822896" target="_blank">9314822896</a> mem after closing files & GC<br>
<br>
I have also checked, whether memory is freed a couple of minutes after closing the images, which does not appear to be the case.<br>
<br>
Note that scifio is also somewhat slower, although I'm a bit hesitant to bring this up, because it is still relatively young and I can see a few "improve ... performance" tickets in the issue tracker.<br>
<br>
Below is the macro.<br>
Kind regards,<br>
Burkhard<br>
<br>
<br>
nOpenTimes = 3;<br>
file = "/path/to/stack";<br>
<br>
run("Collect Garbage");<br>
memBefore = IJ.currentMemory();<br>
<br>
msToOpen = getTime();<br>
for (i=0; i<nOpenTimes; i+=1) {<br>
open(file);<br>
}<br>
msToOpen = getTime() - msToOpen;<br>
<br>
memFilesOpen = IJ.currentMemory();<br>
run("Collect Garbage");<br>
memFilesOpenGC = IJ.currentMemory();<br>
<br>
for (i=0; i<nOpenTimes; i+=1) {<br>
close();<br>
}<br>
memFilesClosed = IJ.currentMemory();<br>
run("Collect Garbage");<br>
memFilesClosedGC = IJ.currentMemory();<br>
<br>
print(""+ msToOpen + " ms to open files");<br>
print(""+ memBefore + " mem before opening files");<br>
print(""+ memFilesOpen + " mem after opening files");<br>
print(""+ memFilesOpenGC + " mem after opening files & GC");<br>
print(""+ memFilesClosed + " mem after closing files");<br>
print(""+ memFilesClosedGC + " mem after closing files & GC");<br>
<br>
______________________________<u></u>_________________<br>
SCIFIO mailing list<br>
<a href="mailto:SCIFIO@scif.io" target="_blank">SCIFIO@scif.io</a><br>
<a href="http://scif.io/mailman/listinfo/scifio" target="_blank">http://scif.io/mailman/<u></u>listinfo/scifio</a><br>
</blockquote></div><br></div>