[Haskell-cafe] GC'ing file handles and other resources

Duncan Coutts duncan.coutts at worc.ox.ac.uk
Fri Apr 18 05:53:54 EDT 2008


On Wed, 2008-04-16 at 11:00 +0530, Abhay Parvate wrote:
> Your mail gives me an idea, though I am not an iota familiar with
> compiler/garbage collector internals. Can we have some sort of
> internally maintained priority associated with allocated objects? The
> garbage collector should look at these objects first when it tries to
> free anything. The objects which hold other system resources apart
> from memory, such as file handles, video memory, and so on could be
> allocated as higher priority objects. Is such a thing possible?

The way I have imagined this when I've faced Conal's problem in the past
(again to do with graphics libs and large foreign allocated bitmaps) is
to assign an optional heap memory equivalent cost to ForeignPtrs.
Basically the idea is to take the foreign memory allocations into
account when considering heap pressure. At the moment a ForeignPtr only
counts for about 10 words of heap pressure when of course it can
represent hundreds of kilobytes. So by assigning a cost we can take that
into account with the normal decisions about when to do a minor and
major GC.

We should be able to treat a ForeignPtr to foreign allocated memory in
just the same way as a ForeignPtr to heap allocated memory in terms of
timing/frequency of GC behaviour.

Of course it doesn't help with all resources since not all are
equivalent to memory, eg the arbitrary limits some OSs impose on the
number of open file handles.

Duncan



More information about the Haskell-Cafe mailing list