When using the Haskell HDBC-ODBC library to connect to a Microsoft SQL Server I am experiencing a bad memory leak.
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 <- ODBC.connectODBC connStr
replicateM_ 20000 (loop conn)
disconnect conn
where
loop c = do
result <- getTables c
commit c
putStrLn $ show result
Running the heap profiler gives me constant memory usage but Window reports memory increasing to almost 100MB of usage.
http://i.stack.imgur.com/YkUTW.png
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.
Are there any alternatives to using HDBC-ODBC? If not, I might need to learn F#.
The issue was in the hdbc-odbc library. A new version v2.5 is available from the Git repo but the hdbc library also needs to be patched to work.
More details available at this bug report.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With