[Haskell-cafe] Re: Are handles garbage-collected?

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Sun Oct 24 11:55:09 EDT 2004


Peter Simons <simons at cryp.to> writes:

> I wish that were possible! I use bracket-style resource
> allocation wherever I can, but in this case the Handle is
> the _result_ of a rather complex computation, so it has to
> leave the scope in which is was opened. A finalizer is all I
> can use.

It does not necessarily make bracket unavailable. Just put it
somewhere outside, when it's known when the file will need to be
closed.

The whole action which opens the file inside it should be the
"acquire" part of the bracket. Asynchronous exceptions will be blocked
during executing it, so it should not be too long unless it unblocks
them for longer parts.

Of course there are also some cases when the file handle is deeply
buried in some data structures, and we don't know when they will be
freed.

-- 
   __("<         Marcin Kowalczyk
   \__/       qrczak at knm.org.pl
    ^^     http://qrnik.knm.org.pl/~qrczak/


More information about the Haskell-Cafe mailing list