[Haskell-cafe] IORef memory leak

Ross Mellgren rmm-haskell at z.odi.ac
Fri Jun 19 01:00:56 EDT 2009


D'oh, yeah that is better. You know, I actually had that and had  
expanded it because I was going to seq both the input and the result  
of the (+1), but punted on it and didn't switch back to the more  
compact format.

-Ross

On Jun 19, 2009, at 12:45 AM, Luke Palmer wrote:

> On Thu, Jun 18, 2009 at 9:55 PM, Ross Mellgren <rmm- 
> haskell at z.odi.ac> wrote:
> It looks offhand like you're not being strict enough when you put  
> things back in the IORef, and so it's building up thunks of (+1)...
>
> With two slight mods:
>
>
>   go 0 = return ()
>   go n = do modifyIORef ior (+1)
>             go (n-1)
>
> -->
>
>   go 0 = return ()
>   go n = do modifyIORef ior (\ x -> let x' = x+1 in x `seq` x')
>             go (n-1)
>
> Just a slight prettification of that line:
>
> modifyIORef ior ((1+) $!)
>
> Or applied prefix if you prefer.  Prefix ($!) has the nice  
> interpretation as the HOF that makes its argument into a strict  
> function.
>
> Luke
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090619/0f9ff4a3/attachment.html


More information about the Haskell-Cafe mailing list