[Haskell-cafe] Re: garbage collector woes

Chris Waterson waterson at maubi.net
Thu Feb 19 19:29:33 EST 2009

On Feb 19, 2009, at 3:41 PM, Don Stewart wrote:

> Is the solution written up somewhere so we can point to that next  
> time?
> :)

Well, the applicability to the community at large is probably minimal,  
but my misadventure follows...

The MySQL C API has "statements" that are associated with a database  
"connection".  You connect to the database, and issue statements to  
query and manipulate it.  The statement encapsulates, basically, the  
state of iteration through a result set.

It turns out that a connection allows only one statement to be active  
at a time, and that "closing" any statement associated with a  
connection appears to close all other statements associated with that  
connection, too.  I wrap the MySQL "statement" in a ForeignPtr whose  
finalizer closes the statement.  Which, as it turns out, would close  
the *next* statement that I'd created on the connection as a side  
effect.  I was incorrectly interpreting

I tried to mitigate this surprising effect by 1) making sure that a  
statement gets finalized as soon as its result set is exhausted, and  
2) adding some warnings to the driver docs about this wonderful feature.


More information about the Haskell-Cafe mailing list