[Haskell-cafe] guided seq (Was: Interruptible threads with IO loops)
Joachim Breitner
mail at joachim-breitner.de
Wed Dec 21 10:31:10 CET 2011
Hi,
Am Mittwoch, den 21.12.2011, 19:15 +1000 schrieb Gregory Crosswhite:
> I don't have any tips for cleaning up the code off the top of my head,
> but I suspect that the memory leak is coming from the fact that the
> expression (v+1) is not being forced, which means that each iteration
> of the loop is constructing a new thunk with a reference to the old
> thunk resulting in a data structure that is growing in memory usage
> over time.
this problem comes up in various places; forcing the whole thunk is of
course an option, but would it be possible – theoretical, with the GHC
runtime, or even with current tools – to have a function
evaluateUntilItDoesNotNeed :: a -> b -> a
such that
f x `evaluateUntilItDoesNotNeed` x
will not retain a reference to x, but is otherwise as lazy as possible?
If thunks retain references to their free variables, and these can be
introspected, then it should be possible to keep seq’ing those thunks
that refer to x, until the expression is either fully evaluated or no
referenced thunk references x.
This would be particularly handy when with, for example
snd tuple `evaluateUntilItDoesNotNeed` tuple
where the tuple is unevaluated in the right component (and where we
don’t want to force this just now), but retains something large in the
left component (that we want to become GCable).
Greetings,
Joachim
--
Joachim "nomeata" Breitner
mail at joachim-breitner.de | nomeata at debian.org | GPG: 0x4743206C
xmpp: nomeata at joachim-breitner.de | http://www.joachim-breitner.de/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111221/8be6df5b/attachment.pgp>
More information about the Haskell-Cafe
mailing list