On Fri, 8 Oct 2010, Florian Weimer wrote:

At least in my experience, in order to get proper resource management
for things like file or database handles, you need both a close
operation and a finalizer registered with the garbage collector.  The
former is needed so that you can create resources faster than the
garbage collector freeing them.  The latter is a safety net in cases
where proper resource management is not follwoed (perhaps in GHCi).
When the explicit close operation or the finalizer has been invoked,
the object must somehow be disabled, so that further operations on it
fail (otherwise, you might dereference a dangling pointer).

Some open/close pairs have corresponding 'with' functions, that are implemented using Exception.bracket. You can also use them within GHCi. I think using both manual resource deallocation and finalizers makes everything more complicated and more unreliable.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to