4

I tried putting together a resource pool and HDBC the other day but noticed that the memory keeps rising for each query. I then put together a simple test code using as few functions as possible and got this:

data SQL = SQL (Pool Connection)
check :: SQL -> IO ()
check (SQL pool) = do res <- query' pool "show status like 'Threads_conn%'" []
                      threadDelay 100000
                      check (SQL pool)

Whole code: http://upaste.me/40f2229cef7157f

For each recursion of the check function, the program uses more and more memory. Shouldn't the result be garbage collected at a new recursive call or will it stay in memory until the program exits that function in case "we need it"?

7
  • 1
    Garbage collection doesn't happen until the heap fills up. What happens if you limit the heap a bit? Check the output of ./yourprogram +RTS -h for information about how to do this. Commented Apr 26, 2012 at 5:18
  • I limited the heap with ./program +RTS -H4096K and as before, the program builds up memory used for each recursive call.
    – Plankt
    Commented Apr 26, 2012 at 7:46
  • It is possible that HDBC has finalizers attached to foreign objects, that aren't deallocated until a major GC occurs. Since the GC doesn't know the size of the foreign object, it doesn't see it as contributing to heap pressure, resulting in fewer GCs. HDBC might also just not be freeing required resources. Try an explciit performGC Commented Apr 26, 2012 at 11:44
  • try rewriting with an explicit forever as well...
    – sclv
    Commented Apr 26, 2012 at 17:26
  • Neither performGC nor forever solves the issue at hand. I'm starting to think it's an issue with the library HDBC itself. It might also be that since I have a reference to the pool through the threads, the GC doesn't collect the information as wanted.
    – Plankt
    Commented Apr 27, 2012 at 1:51

1 Answer 1

1

Late followup, but depending on the version of pool you were using, it may have been a bug with the pool implementation itself: https://github.com/bos/pool/pull/4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.