Haskell: how to detect “lazy memory leaks”

前端 未结 3 648
小鲜肉
小鲜肉 2021-01-30 02:39

After few hours of debugging, I realized that a very simple toy example was not efficient due to a missing ! in an expression return $ 1 + x (thanks du

3条回答
  •  再見小時候
    2021-01-30 03:10

    There is a specific class of space leaks that can be detected because they use excessive amounts of stack when they unwind the excessive heap usage. The following website lists the specific approaches, along with lots of case studies, but roughly:

    • Compile and run with a limited size stack, using +RTS -K10K to limit the stack to 10Kb.
    • Examine the code that breaks the stack limit, using +RTS -xc to get stack traces.

    It's not a perfect approach since sometimes you have memory leaks without excessive stack usage, and sometimes you have excessive stack usage without memory leaks, but the correspondence is pretty good and the tooling can be deployed on CI to stop introducing new leaks.

提交回复
热议问题