[Haskell-cafe] Are handles garbage-collected?

Remi Turk rturk at science.uva.nl
Sun Oct 24 16:07:39 EDT 2004


On Sun, Oct 24, 2004 at 12:19:59PM -0700, Conal Elliott wrote:
> I'm puzzled why explicit bracketing is seen as an acceptable solution.
> It seems to me that bracketing has the same drawbacks as explicit memory
> management, namely that it sometimes retains the resource (e.g., memory
> or file descriptor) longer than necessary (resource leak) and sometimes
> not long enough (potentially disastrous programmer error).  Whether the
> resource is system RAM, file descriptors, video memory, fonts, brushes,
> bitmaps, graphics contexts, 3D polygon meshes, or whatever, I'd like GC
> to track the resource use and free unused resources correctly and
> efficiently.
> 
> Cheers,
> 
>      - Conal

IMO, it does indeed have those same drawbacks. (Although the
traditional "explicit memory management model" is alloc/free,
which is much worse than bracket/withFile)
However, Garbage Collection is usually based only on memory.
Using GC for file-handle-closing therefore means that one will
close garbage file-handles when memory is getting low, instead of
when file-handles are almost used up...
The theoretical solution (and probably _only_ theoretical) is
implementing a lot of garbage collectors: one for memory, one for
open files, one for sockets, one for 3D polygon meshes etc etc...

Greetings,
Remi

-- 
Nobody can be exactly like me. Even I have trouble doing it.


More information about the Haskell-Cafe mailing list