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 m...@joachim-breitner.de | nome...@debian.org | GPG: 0x4743206C xmpp: nome...@joachim-breitner.de | http://www.joachim-breitner.de/
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe