On Tue, Mar 23, 2010 at 4:04 PM, Bas van Dijk <v.dijk.bas@gmail.com> wrote:
On Tue, Mar 23, 2010 at 10:20 PM, Simon Marlow <marlowsd@gmail.com> wrote:
> The leak is caused by the Data.Unique library, and coincidentally it was
> fixed recently.  6.12.2 will have the fix.

Oh yes of course, I've reported that bug myself but didn't realize it
was the problem here :-)

David, to clarify the problem: newUnqiue is currently implemented as:

newUnique :: IO Unique
newUnique = do
  val <- takeMVar uniqSource
  let next = val+1
  putMVar uniqSource next
  return (Unique next)

You can see that the 'next' value is lazily written to the uniqSource
MVar. When you repeatedly call newUnique (like in your example) a big
thunk is build up: 1+1+1+...+1 which causes the space-leak. In the
recent fix, 'next' is strictly evaluated before it is written to the
MVar which prevents a big thunk to build up.

regards,

Bas

Thanks for this excellent description of what's going on.  This whole thread has been a reminder of what makes the Haskell community truly excellent to work with.  I appreciate everything you guys are doing!

Dave