Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What are the first line of a heap dump that are not address ? #1

Open
tenderlove opened this issue Apr 7, 2017 · 1 comment
Open

Comments

@tenderlove
Copy link

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:

abc

But say we have this:

a = "foo"
b = "bar"
c = { a => b }
GC.start
p c

What 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:

roots

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:

total

Hope that helps!

@benoittgt
Copy link
Owner

Thanks a lot @tenderlove. That's perfect. I now understand the header. I've added your answer to the readme (#4)

Will try to search for vm, finalizers and others. 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants