
Hi all, Is there a way to achieve the effect of soft references in GHC? Or if not, is there any hope that they will be implemented in the future? (Soft references are like weak references, except that they are only reclaimed by the garbage collector if memory is short.) I'm building a memoization table of visualizations of a data set, but I can't store *all* visualizations of that set in memory at the same time. My current solution is to use a least-recently-used cache, but this is unsatisfying because I have to specify the maximum number of objects in the cache; if I make that too large, I run out of memory, so I have to make it so small that I can't possibly run out, meaning that I have to make it a lot smaller than it *could* be. With soft references, the program could memoize the "optimal" number of items, with the user being able to influence the behavior through the 'maximum heap size' RTS option. Any ideas? Thanks, - Benja

On Wed, 2007-04-18 at 16:17 +0300, Benja Fallenstein wrote:
Hi all,
Is there a way to achieve the effect of soft references in GHC? Or if not, is there any hope that they will be implemented in the future? (Soft references are like weak references, except that they are only reclaimed by the garbage collector if memory is short.)
Oh, and we could do mmap-like things for lazy random IO on (read-only) files. Take a finger tree of strict chunks where each chunk is lazily read in from a span in the file (using unsafeInterleaveIO and seek) but then instead of holding that chunk in memory for evermore (well, at least as long as the whole finger tree is kept alive) if that chunk is not being used any more and only being referenced through the finger tree then when memory is tight we can just forget it and re-read it later if we get asked for it again. This might work with weak references at the moment but 'soft' references would probably suit it better. Duncan
participants (2)
-
Benja Fallenstein
-
Duncan Coutts