logo       

Re: Do I need to close a FileStream?: msg#00144

lang.smalltalk.squeak.beginners

Subject: Re: Do I need to close a FileStream?

The underlying OS has only a certain number of file handles that it
can maintain open at a time. On UNIX-like systems, there is also
possibly a maximum number of files per process. If this limit is hit,
then no additional files can be opened, and on any attempt to do so an
error is returned.

-Kyle H

On 3/24/07, Bert Freudenberg <bert@xxxxxxxxxxxxxxx> wrote:
On Mar 24, 2007, at 8:34 , Tim Johnson wrote:

> Hi,
>
> Do I need to worry about closing a read-only FileStream when I am
> done reading from it?

Yes. Always. A common pattern is

f := ... open the file stream ....
[ ... do something with f ... ] ensure: [f close]

This ensures f is closed even if there is an error in your processing
code.

> What happens if I don't?

Bad Things ;) I'm not exactly sure.

> How can I tell if I have lots of open files in my system?
> "FileStream allInstances inspect"?

You would need to use #allSubInstances and check if they're open.

- Bert -


_______________________________________________
Beginners mailing list
Beginners@xxxxxxxxxxxxxxxxxxxxxxxxxx
http://lists.squeakfoundation.org/mailman/listinfo/beginners



--

-Kyle H


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise