title: Haskell HDBC-ODBC Memory Leak?
body: <p>When using the Haskell HDBC-ODBC library to connect to a Microsoft SQL Server I am experiencing a bad memory leak.</p>
  
  <pre><code>import           Database.HDBC        
  import qualified Database.HDBC.ODBC   as ODBC
  import           Control.Monad
  
  -- | Main application.
  main :: IO ()
  main = dbTest
  
  dbTest :: IO ()
  dbTest = do
      let connStr = "DSN=TESTDB;Uid=sa;Pwd=password"
      conn &lt;- ODBC.connectODBC connStr
      replicateM_ 20000 (loop conn)
      disconnect conn
    where
      loop c = do
          result &lt;- getTables c
          commit c
          putStrLn $ show result
  </code></pre>
  
  <p>Running the heap profiler gives me constant memory usage but Window reports memory increasing to almost 100MB of usage.</p>
  
  <p><a href="http://i.stack.imgur.com/YkUTW.png">http://i.stack.imgur.com/YkUTW.png</a></p>
  
  <p>To me this seems like the memory leak is in the Foreign Function interface of the ODBC driver, but this is my first time profiling code so I can't be certain. Does anyone have any further insight or suggestions for a fix? Calling System.Mem.performGC in the loop to try and clean up has no effect.</p>
  
  <p>Are there any alternatives to using HDBC-ODBC? If not, I might need to learn F#.</p>