StandardFileStream not closing files immediately

David T. Lewis lewis at mail.msen.com
Tue Dec 28 16:29:35 UTC 2004


On Tue, Dec 28, 2004 at 04:13:06PM +0800, Yar Hwee Boon wrote:
> I'm having problems deleting a file after closing its file stream and it  
> seems to be described in this thread  
> http://lists.squeakfoundation.org/pipermail/squeak-dev/2004-February/074560.html.  
> A gc seems to fix it. Is there a way to explicitly close it *immediately*?  
> Thanks.

Yes there is a way.
 
StandardFileStream>>finalize is what closes the file when the garbage 
collector runs, but this is not the way you would normally want to
close the resource. It's just sort of the method of last resort if you
did not remember to close the file explicitly.

StandardFileStream>>close is the method that closes the file cleanly
and makes sure that the external file handle gets closed. If you
use this to explicitly close all file streams that refer to the 
file, you should then be able to delete the file.

Both #finalize and #close will call the same #primitiveFileClose
method (which you can find in class FilePlugin if you have VMMaker
loaded). So just use #close on any open file streams connected to
the file, all should be well.

Dave




More information about the Squeak-dev mailing list