[Haskell-cafe] Soft references

Benja Fallenstein benja.fallenstein at gmail.com
Wed Apr 18 09:17:07 EDT 2007


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


More information about the Haskell-Cafe mailing list