PixInsight Forum (historical)
Software Development => PCL and PJSR Development => Topic started by: Mike Reid on 2011 December 17 10:40:06
-
I've been working on a script that loops through opening and closing a large number of files. It kept crashing PI and I wasn't sure why. I reduced the script to just a loop that opens and closes files and does nothing else, like this,
this.testLoop = function(files) {
for ( var i = 0; i < files.length; ++i ) {
var w = ImageWindow.open( files );
w.close;
}
}
If I monitor this while running I see that the memory usage of PI just keeps increasing. No memory ever gets freed by the close.
What am I doing wrong?
Thanks,
Mike
-
Hello Mike,
Try...
w.close();
(notice the parentheses () at the end)
Or if the image has been modified...
w.forceClose();
Hope this help,
Enzo.
-
Thanks for the reply Enzo but unfortunately when I try close() I get this error,
TypeError: w.close is not a function
Same with forceClose().
Thanks,
Mike
-
Hi Mike,
var w = ImageWindow.open( files );
w.close();
ImageWindow.open() returns an *array* of ImageWindow objects. This is because several file formats support multiple images stored in a single file (e.g. the FITS format). So 'w.close()' doesn't work because close() is not a method of the Array object.
This code should work:
var w = ImageWindow.open( "/path/to/my/file.fit" );
for ( var i in w )
w[i].close();
Of course this is just an example---opening something to close it immediately isn't a very useful operation. This is a more elaborated example:
var w = ImageWindow.open( "/path/to/my/file.fit" );
for ( var i in w )
{
w[i].show();
w[i].zoomToOptimalFit();
}
As Enzo has pointed out, sometimes one wants to close an image unconditionally, even if the image has been modified. In these cases ImageWindow.forceClose() closes an image window immediately without further questions.
Hope this helps
-
That fixed it, thanks Juan!
I wrote a script that sorts through a directory full of calibration frames, looks at the fits header, sorts them in memory by type (bias, dark, flat), filter, exposure time and temperature and builds master calibration frames. It crashed my linux box when I ran it on a directory with a couple of hundred 6 megapixel images because I was not closing the images correctly.
Mike
-
Hi Mike,
Sounds like a great script. Hope you'll share it with the rest of us. Love to give it a try.
Have a great Holiday.
Steve