[Haskell-cafe] IORef memory leak
qdunkan at gmail.com
Fri Oct 15 13:48:16 EDT 2010
> The latter. atomicModifyIORef is harder though still, since it is a
> primop with the same properties as modifyIORef :/
>> So would it make sense to create a strict modifyIORef' function?
> Very much so. In fact, I'd argue the vast majority of uses are for the
> WHNF-strict version.
I just fixed a leak with atomicModifyIORef that was exactly this
problem. If it had at least been documented I wouldn't have had to do
that. So I'm going to submit a library proposal to either 1)
strictify atomicModifyIORef, 2) add atomicModifyIORef', or at the
least 3) add documentation that says "this function leaks". Same
story for modifyIORef of course.
The only workaround I could find is to immediately read the value back
out and 'seq' on it, but it's ugly.
So two questions:
writeIORef doesn't have this problem. If I am just writing a simple
value, is writeIORef atomic? In other words, can I replace
'atomicModifyIORef r (const (x, ())' with 'writeIORef r x'?
Any reason to not do solution 1 above?
More information about the Haskell-Cafe