-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Those are "ROOTS" (the ones with type = "ROOTS"). The system has various "roots".
What is a "ROOT"?
Objects in the system form a tree data structure. Imagine some code like this:
a = "foo"
b = "bar"
c = { a => b }It's easy to see how c is connected to a and b and prevents them from being garbage collected:
But say we have this:
a = "foo"
b = "bar"
c = { a => b }
GC.start
p cWhat prevents c from being garbage collected? Something must hold a reference to c so that the garbage collector can know that it shouldn't be GC'd. This is where ROOTS come in. Roots are special nodes in the system that hold on to these references:
MRI has a few different places it considers a root, and those are in the name root (like vm, finalizers, etc). Explaining each of these types is a little too long for here, but you can think of them as the root of the tree that forms your object graph. They keep your program objects alive, and they are the starting point for the GC to find live objects in your system. In fact the graph I showed above is a little inaccurate. Since a and b are also top level local variables like c, the graph looks a bit more like this:
Hope that helps!


