Was there a specific reason garbage collection was

2019-01-17 00:35发布

I have heard that it was suboptimal for C to automatically collect garbage -- is there any truth to this?

Was there a specific reason garbage collection was not implemented for C?

13条回答
霸刀☆藐视天下
2楼-- · 2019-01-17 01:18

Garbage Collection is not useful if you want to make hardcore optimisations, because if you decide the moment when it's best to free allocated space, then you can make a much better job in your project than the garbage collector does. In the 1970s I don't know the exact cause why the developers decided to not include a garbage collector to C, probably they wanted to have absolute control of deallocation, however I'm sure later they didn't even consider to add a garbage collector, because even if there is an integration of a garbage collector to the language which is very good, there were built a lot of C projects and the new versions of the language must have backwards compatibility.

EDIT: "There are also compilers, libraries and operating system level mechanisms for performing array bounds checking, buffer overflow detection, serialization and automatic garbage collection, that are not a standard part of C." This may be interesting for you, you can read more here.

查看更多
登录 后发表回答