Improve space profiling for references
|Reported by:||simonpj||Owned by:|
|Type of failure:||None/Unknown||Test Case:|
|Related Tickets:||Differential Rev(s):|
GHC's great space profiling tools don't appear to be much help when your leaked memory is stored in references (IORefs, StablePtrs, etc). I had a real-life case where the allocation profile showed me where the leaked data came from, and I could guess that it was being held by some reference, but I couldn't tell which one. Retainer set profiling showed a big suspicious entry for "SYSTEM", but I couldn't find any way to pinpoint the problem. (It ended up being a missing freeStablePtr in hsgnutls, found by code inspection.)
Here's a contrived example that just allocates a bunch of IORefs:
import Control.Monad import Data.IORef main = repeatM (newIORef [1,2,3]) repeatM io = liftM2 (:) io (repeatM io)
Retainer set profiling shows everything in "SYSTEM". None of the other profiling methods say anything interesting either. What I'd like to get, I think, is (1) your memory is being held in IORefs (2) allocated by this cost center and (3) being retained by this cost center. I guess I'm looking for something like a memory profiler for a traditional language.
Simon Marlow comments: "The relevant predicate "is retainer" is pretty much built into the retainer profiler, and it returns true only for thunks if I recall correctly. Being able to tweak this, or maybe just install a better default would be an improvement.