Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

10
  • 53
    @ChristianDean Note that even C has a runtime library. While it doesn't have GC, it still performs memory management through that runtime library: malloc() and free() are not built in to the language, are not part of the operating system, but are functions in this library. C++ is also sometimes compiled with a garbage collection library, even though the language was not designed with GC in mind. Commented Jun 14, 2017 at 7:29
  • 18
    C++ also contains a runtime library that does things like make dynamic_cast and exceptions work, even if you don't add a GC. Commented Jun 14, 2017 at 8:04
  • 23
    The runtime library is not necessarily copied into each executable (which is called static linking) it may only be referenced (a path to the binary containing the library) and accessed at execution time: this is dynamic linking. Commented Jun 14, 2017 at 8:06
  • 17
    The compiler is also not required to directly jump into your program's entrypoint without anything else happening. I'm making an educated guess that every compiler actually inserts a bunch of platform-specific initialisation code before it calls main(), and it's perfectly legal to, say, fire up a GC thread in this code. (Assuming the GC isn't done inside memory allocation calls.) At runtime, GC only really needs to know what parts of an object are pointers or object references, and the compiler needs to emit the code to translate an object reference to a pointer if the GC relocates objects. Commented Jun 14, 2017 at 9:43
  • 16
    @millimoose: Yes. For example, on GCC, this piece of code is crt0.o (Which stands for "C RunTime, the very basics"), which gets linked with every program (or at least every program that isn't free-standing). Commented Jun 14, 2017 at 12:57