Why don't Haskell compilers facilitate deterministic memory management?

前端 未结 5 1603
栀梦
栀梦 2021-02-02 11:48

With the wealth of type information available why can\'t Haskell runtimes avoid running GC to clean up? It should be possible to figure out all usages and insert appropriate cal

5条回答
  •  时光取名叫无心
    2021-02-02 12:28

    Region-based memory management is what programmers in C and C++ often end up programming by hand: Allocate a chunk of memory ("region", "arena", etc.), allocate the individual data in it, use them and eventually deallocate the whole chunk when you know none of the individual data are needed any more. Work in the 90s by Tofte, Aiken, and others (incl. yours truly, with our respective colleagues), has shown that it is possible to statically infer region allocation and deallocation points automatically ("region inference") in such a way as to guarantee that chunks are never freed too early and, in practice, early enough to avoid having too much memory being held for long after the last data in it was needed. The ML Kit for Regions, for example, is a full Standard ML compiler based on region inference. In its final version it is combined with intra-region garbage collection: If the static inference shows there is a long-living region, use garbage collection inside it. You get to have your cake and eat it, too: You have garbage collection for long living data, but a lot of data is managed like a stack, even though it would end in a heap ordinarily.

提交回复
热议问题