How much extra memory does garbage collection require?

后端 未结 4 1418
死守一世寂寞
死守一世寂寞 2021-02-07 13:45

I heard once that for a language to implement and run garbage collection correctly there is on average of 3x more memory required. I am not sure if this is assuming the

4条回答
  •  广开言路
    2021-02-07 14:27

    So i wanted to know if theres any research or actually numbers of garbage collection overhead.

    Almost 10 years ago I studied two equivalent programs I had written in C++ using the STL (GCC on Linux) and in OCaml using its garbage collector. I found that the C++ used 2x more memory on average. I tried to improve it by writing custom STL allocators but was never able to match the memory footprint of the OCaml.

    Furthermore, GCs typically do a lot of compaction which further reduces the memory footprint. So I would challenge the assumption that there is a memory overhead compared to typical unmanaged code (e.g. C++ using what are now the standard library collections).

提交回复
热议问题