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"?

Plankt
  • 135
  • 4
  • 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. – Daniel Wagner Apr 26 '12 at 05:18
  • I limited the heap with `./program +RTS -H4096K` and as before, the program builds up memory used for each recursive call. – Plankt Apr 26 '12 at 07: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` – Don Stewart Apr 26 '12 at 11:44
  • try rewriting with an explicit `forever` as well... – sclv Apr 26 '12 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 Apr 27 '12 at 01:51
  • At this point yes, I think its the ODBC-HDBC library causing the problem. There are lots of tricky bits in that binding. Nicholas Wu (http://zenzike.com/about) was doing some work on it last, I think, so you may want to contact him as well as Goerzen. – sclv Apr 27 '12 at 18:48
  • Try to do manual commit after each query. – Dalibor Filus Dec 11 '12 at 14:36

1 Answers1

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

sclv
  • 38,665
  • 7
  • 99
  • 204