
On Thu, Feb 12, 2009 at 10:36 AM, Simon Marlow
Peter Verswyvelen wrote:
Yes, I was really surprised that this was the case. I while ago I did a little FRP experiment. I made a top level binding to a list of timer event occurrences. The list was generated on another thread. To my surprise, I did not have space leak, which is amazingly cool, but it felt odd :) Is it documented when GHC will garbage collect CAFs?
CAFs are garbage collected when they are unreachable by traversing the code that is reachable from the currently running program. In practice we don't actually traverse the code, instead we have these "static reference tables" that list the top-level closures referenced by each code block, and traverse those instead.
Unfortunately we didn't get around to documenting the details of how this works...
Using this as a guide, I tested these two programs: ==== str = concat $ repeat "foo " main1 = print foo main2 = print foo >> print foo ===== As I'm sure you realize, the first ran in constant memory; the second, not so much. Very interesting.