Skip to main content

Posts

Showing posts with the label GHC

Diagnosing Haskell Space Leaks: A Practical Guide to ghc-debug

  The most insidious failure mode in Haskell production systems is the slow-burning memory leak. Your application runs perfectly for days, but the Resident Set Size (RSS) creeps upward until the OOM killer terminates the process. Standard heap profiling ( -hT ) often changes the runtime characteristics enough to hide the bug (the "Heisenbug" effect) or requires restarting the process, destroying the state you need to inspect. The modern solution is  ghc-debug . This toolset allows you to connect to a running Haskell process, inspect the heap graph programmatically, and identify thunk buildup without stopping the world for extended periods or recompiling with heavy instrumentation. The Root Cause: Thunks and WHNF Haskell’s memory leaks are rarely "leaks" in the C/C++ sense (unfreed memory). They are almost always  unwanted retention . Because Haskell is lazy, an expression like  acc + 1  is not evaluated immediately. It allocates a "thunk" (a closure repres...