How to disable Garbage Collection in GHC Haskell?

(With the help from carter in #ghc on freenode)

There is no switch to completely disable GC. Instead, use all of the following +RTS runtime options:

  • Disable idle time garbage collection using -I0.
  • Set the "nursery" == "allocation area" size to something very large, e.g. -A100G, as GC will only be done when the allocation area is full.

See https://downloads.haskell.org/~ghc/7.8-latest/docs/html/users_guide/runtime-control.html for a description of these options.

Be aware that you will run out of RAM quickly.


I had good results combining nh2 and Thomas's answers into

+RTS -I0 -A90G -G1 -m1 -RTS

I have 100 GB of RAM, so I thought 90G was a good allocation area size.

I also used System.Mem.performGC to manually trigger GC at appropriate points and GHC.Stats to keep track of how much time has been spent in GC.

Tags:

Haskell

Ghc