Why am I wrong about GC?

To be clear at the top, I don’t have practical or theoretical background in language/compiler/memory management design. This is not a proposal for an improvement to Julia’s garbage collection. I have one of those “isn’t the solution simple?” ideas that only a total novice could think.

Why does GC need to freeze the operation of all threads to do a sweep?

As long as you have multiple threads available and you are only collecting objects in the “old generation” which have fallen out of scope for all processes, why couldn’t a thread managing GC free those memory locations while the other threads continue their worth?

you are only collecting objects in the “old generation” which have fallen out of scope for all processes

I’m a bit confused by what you mean. I’ve understood the old generation as being those objects that have repeatedly survived the collection process because they are still alive. But you seem to be implying almost the opposite if I understand you.

If you know that an object isn’t in scope anymore you don’t need a GC to free it, You need a GC to free memory the memory that doesn’t have an easily determinable lifetime from static analysis. The way you find the dead objects is by searching the memory graph of the entire application, which is why you need to freeze all the threads (unless you do fancy stuff that Julia doesn’t do).

5 Likes

Object lifetime is decoupled from lexical scope in Julia. E.g., the last reference to an object might be buried in a linked list. Hence the need for garbage collection to walk the object graph.

Concurrent garbage collectors are well known. e.g. Dijkstra’s tri-color collection algorithm dates back to 1978. But the algorithm may actually slow down overall execution speed as noted here.

The Go language has a state of the art concurrent collector, albeit Go rewrote the world – they have their own calling convention, compiler, linker). To learn more about concurrent garbage collection in a production language, this keynote talk is work reading: Getting to Go: The Journey of Go's Garbage Collector - The Go Programming Language

14 Likes

A post was split to a new topic: Increase the ‘aggressiveness’ of the garbage collection?

Thanks, everyone!

@johnmyleswhite Shows you my ignorance here using vocab I’ve heard but don’t fully understand. I had assumed “old generation” meant no longer used. Thanks for the clarification.

@arch.d.robison That’s much clearer now. I read the Go talk and got some of it, but I’ll go back through it again soon.

1 Like