The Garbage Collection Handbook
gchandbook.org268 points by andsoitis a day ago
268 points by andsoitis a day ago
My favorite story about garbage collection: https://devblogs.microsoft.com/oldnewthing/20180228-00/?p=98...
They do that in other places.
As I heard the tale, on the Standard Missile, they don't recirculate the hydraulic fluid, they just spit out as the missile flies. It's a wonderful engineering solution.
And on the Falcon 9, the hydrocarbon fuel is used as hydraulic fluid, then just dumped back into the fuel tank.
And the SR-71 uses its fuel as coolant.
"There was a lot we couldn't do, but we were the fastest kids on the block..."
I would call that a region-based memory allocator... Only that it has a single region, ever.
Yeah if you have for example a http request, you can just collect garbage you create during that request in a single region, then throw it away when the request has been handled. This is quite standard.
It’s pretty standard in many places I think - the point here is not the null gc but rather exact memory requirements being proved statically.
This is one of my favourite anecodtes to tell peers and colleagues because it's important when understanding buisness case/needs against programming. We all want to make perfect software, but it isn't always neccessary.
now that is what i call the ultimate in garbage collection technology
I think the missile impact creates a lot more garbage spread over a wider area.
I wish the author section provided what production garbage collectors the authors worked on. There's plenty of nonintuitive things you can learn in the real world, so a book including those would be both interesting and useful.
Great book. Previous discussion: https://news.ycombinator.com/item?id=35492307
(387 points, 166 comments)
I see that there is a section (relatively short) on real time GC. But for anyone who has read the Handbook, how much emphasis is placed on GC in constrained environments. I have fought the urge to implement a 3D, modern AA game with GC just to prove it is viable outside all but the most resource poor platforms or the most AAAAA, cutting edge, every cycle counted, hyper optimized game. But I am transitioning to a slightly less focused area of responsibility at work and may have some free time to prototype and this may be how I spend my winter and spring free time.
I think you would be hard-pressed to find a modern AA game that does not already use a GC. The major game engines Unreal and Unity are garbage collected - although they use manual memory management for some of their internals, the exposed API surface (including the C++ API) is designed with garbage collection in mind.
Notably, the popular-with-hobbyists Godot Engine does not use a garbage collector. It uses reference counting with some objects, but does not provide cycle detection, thus requires all objects to be laid out in a tree structure (which the engine is built around).
Reference counting is chapter 5 on the linked book.
I said "a GC", that is, "a garbage collector". Even if you consider reference counting as technically being garbage collection, purely reference counted systems do not have a distinct entity that can be identified as "a" garbage collector. So I'm technically correct here even in face of this pedantry.
Not that I think it's a reasonable approach to language to be pedantic on this. RC being GC is, of course, true from an analytic approach to language: a garbage collection system is defined as a system that collects and frees objects that are unreachable and thus dead; a reference counting pointer collects and frees objects that are unreachable and thus dead; therefore, reference counting is garbage collection.
One problem with this is the vagueness: now, the use of a call stack is garbage collection; after all, returning from a function collects and frees the objects in the stack frame. Leaking memory all over the place and expecting the operation system to clean up when you call `exit()` likewise is "garbage collection".
But more importantly, it's just not how anyone understands the word. You understood perfectly well what I meant when I said "you would be hard-pressed to find a modern AA game that does not already use a GC"; in other words, you yourself don't even understand the word differently. You merely feel an ethical imperative to understand the word differently, and when you failed to do so, used my comment as a stand-in to work through the emotions caused by your own inability to live up to this unfulfilled ethic.
Reference counting isn’t garbage collection.
Just say "tracing garbage collection" to avoid the usual referencing counting arguments.
It absolutely is (and as per another thread under another post, both pjmlp and me are notorious for correcting people on this specific point)
They are not interchangeable. The semantics are observably different. Therefore, RC is not GC.
Reference counting gives you eager destruction. GC cannot.
GC gives lets you have garbage cycles. RC does not.
I think a part of the GC crew reclassified RC as GC to try to gain relevance with industry types during a time when GC was not used in serious software but RC was.
But this is brain damage. You can’t take a RC C++ codebase and replace the RC with GC and expect stuff to work. You can’t take a GC’d language impl and replace the GC with RC and expect it to work. Best you could do is use RC in addition to GC so you still keep the GC semantics.
> Reference counting gives you eager destruction. GC cannot.
Tracing GC can't. Reference counting, which is by definition a GC can. It's like insects vs bugs.
And destructors are a specific language feature. No one says that they are a must have and if you don't have them then you can replace an RC with a tracing GC. Not that it matters, a ladybug is not the same as an ant, but they are both insects.
The best part of these conversations is that if I say “garbage collection”, you have zero doubt that I am in fact referring to what you call “tracing garbage collection”.
You are defining reference counting as being a kind of garbage collection, but you can’t point to why you are doing it.
I can point to why that definition is misleading.
Reference counting as most of the industry understands it is based on destructors. The semantics are:
- References hold a +1 on the object they point to.
- Objects that reach 0 are destructed.
- Destruction deletes the references, which then causes them to deref the pointed at object.
This is a deterministic semantics and folks who use RC rely on it.
This is nothing like garbage collection, which just gives you an allocation function and promises you that you don’t have to worry about freeing.
> https://web.eecs.umich.edu/~weimerw/2008-415/reading/bacon-g...
They are different approaches for the same thing: automatic memory management. (Which is itself a not trivial to define concept)
One tracks liveness, while the other tracks "deadness", but as you can surely imagine on a graph of black and white nodes, collecting the whites and removing all the others vs one by one removing the black ones are quite similar approaches, aren't they?