withFile defeats dead handle closure

Oleg Grenrus oleg.grenrus at iki.fi
Wed Dec 30 19:49:43 UTC 2020


I would be afraid of making this change. File descriptors are a scarce
resource, and relying on non-deterministic GC behavior to free them is
big -1.

Also finalizers are not free in current GC. (Though, you probably cannot
won't that many open files that it would matter).

- Oleg

On 30.12.2020 21.23, David Feuer wrote:
> withFile keeps the handle it creates alive until the user action
> completes. If we want to avoid this, we can. All that's required is to
> capture the weak reference that holds the handle's finalizer. Then
> instead of closing the handle in the end (or on exception) using
> hClose, withFile can run the handle's finalizer. Should we do this? Or
> does it run too much against the idea that handles should be managed
> as explicitly as possible?
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries


More information about the Libraries mailing list