Skip to content

Commit d8f4e07

Browse files
Benoit Tigeotbenoittgt
authored andcommitted
Add answer for header of heap dump
1 parent 8de79e3 commit d8f4e07

File tree

1 file changed

+43
-4
lines changed

1 file changed

+43
-4
lines changed

README.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ Here is a list of questions I have. Feel free to make a PR to answer them.
1212

1313
* Retained Vs Allocated: Does an object that is allocated can turn to be retained because he is still present after few GC ?
1414

15-
* What are the first line of a heap dump that are not address ?
15+
* **[Answered]** What are the first line of a heap dump that are not address ?
1616

17-
header of the heap dump [from heapy gem](https://github.com/schneems/heapy/tree/master/spec/fixtures/dumps) (carefull is 78mo text file)
17+
Header of the heap dump [from heapy gem](https://github.com/schneems/heapy/tree/master/spec/fixtures/dumps) (carefull is 78mo text file)
1818

1919
```ruby
2020
{"type":"ROOT", "root":"vm", "references":["0x7fb4740bc400", "0x7fb4740b79a0", "0x7fb4740dff68", "0x7fb4740bff60", "0x7fb4740bff10", "0x7fb474c13a88", "0x7fb474ac0618", "0x7fb4740bfe98", "0x7fb4740bfe70", "0x7fb4740ddc68", "0x7fb4740dff90", "0x7fb4772f88d8", "0x7fb4772f8900"]}
@@ -23,8 +23,47 @@ Here is a list of questions I have. Feel free to make a PR to answer them.
2323
{"type":"ROOT", "root":"global_list", "references":["0x7fb4759d3678", "0x7fb4759d3768", "0x7fb4759d3790", "0x7fb4759d37e0", "0x7fb4759d3808", "0x7fb4759d3830", "0x7fb4759d38d0", "0x7fb4759d3920", "0x7fb4759d3970", "0x7fb4759d3998", "0x7fb4759d39e8", "0x7fb4759d3a10", "0x7fb4759d3a38", "0x7fb4759d3a88", "0x7fb4759d3ab0", "0x7fb4759d3ad8", "0x7fb4759d3b00", "0x7fb4759d3b28", "0x7fb4759d3b78", "0x7fb4759d3ba0", "0x7fb4759d3bc8", "0x7fb4759d3bf0", "0x7fb4759d3c18", "0x7fb4759d3c40", "0x7fb4759d3c68", "0x7fb4759d3c90", "0x7fb4759d3cb8", "0x7fb4759d3ce0", "0x7fb4759d3d58", "0x7fb4759d3dd0", "0x7fb4759d3df8", "0x7fb4759d3e20", "0x7fb4759d3e70", "0x7fb4759d3ee8", "0x7fb4759d3f10", "0x7fb4759d3fb0", "0x7fb474135fa8", "0x7fb4741353c8", "0x7fb474134270", "0x7fb474134298", "0x7fb4741342c0", "0x7fb4741342e8", "0x7fb474134310", "0x7fb474134338", "0x7fb474134360", "0x7fb474134388", "0x7fb4741343b0", "0x7fb4741343d8", "0x7fb474134428", "0x7fb474134450", "0x7fb474134478", "0x7fb4741344a0", "0x7fb4741344c8", "0x7fb4741344f0", "0x7fb474134518", "0x7fb474134540", "0x7fb474134568", "0x7fb474134590", "0x7fb474134608", "0x7fb47481da50", "0x7fb47481dac8", "0x7fb47481db40", "0x7fb47481db68", "0x7fb47481dd20", "0x7fb47481dd98", "0x7fb47481dfa0", "0x7fb47481dfc8", "0x7fb47481e018", "0x7fb47481e040", "0x7fb47481e248", "0x7fb47481e388", "0x7fb47481e5e0", "0x7fb47481e608", "0x7fb47481e6a8", "0x7fb47481e770", "0x7fb47481e7e8", "0x7fb47481e8d8", "0x7fb47481e928", "0x7fb47481e9c8", "0x7fb47481ea40", "0x7fb47481eae0", "0x7fb47481ec48", "0x7fb47481ed88", "0x7fb47481ee28", "0x7fb47481ee50", "0x7fb47481f058", "0x7fb47481f0d0", "0x7fb47481f0f8", "0x7fb47481f210", "0x7fb47481f288", "0x7fb47481f378", "0x7fb47481f418", "0x7fb47481f440", "0x7fb47481f4b8", "0x7fb47481f508", "0x7fb47481f710", "0x7fb47481f738", "0x7fb47481f760", "0x7fb47481fad0", "0x7fb47481fb20", "0x7fb47481fb70", "0x7fb47481fbe8", "0x7fb47584f270", "0x7fb475874700", "0x7fb475874a20", "0x7fb4769904d0", "0x7fb4740dff40"]}
2424
```
2525

26+
**Answered by Aaron Patterson https://github.com/benoittgt/understand_ruby_memory/issues/1**
2627

27-
Partially answered from https://blog.codeship.com/the-definitive-guide-to-ruby-heap-dumps-part-i/ but not the header.
28+
> Those are "ROOTS" (the ones with type = "ROOTS"). The system has various "roots".
29+
30+
> #### What is a "ROOT"?
31+
32+
> Objects in the system form a tree data structure. Imagine some code like this:
33+
34+
```ruby
35+
a = "foo"
36+
b = "bar"
37+
c = { a => b }
38+
```
39+
40+
> It's easy to see how `c` is connected to `a` and `b` and prevents them from being garbage collected:
41+
42+
![abc](http://imgur.com/Rcc08c2.png)
43+
44+
> But say we have this:
45+
46+
```ruby
47+
a = "foo"
48+
b = "bar"
49+
c = { a => b }
50+
GC.start
51+
p c
52+
```
53+
54+
> 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:
55+
56+
![roots](http://imgur.com/5OhGzvI.png)
57+
58+
> 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:
59+
60+
![total](http://imgur.com/P7JFgN8.png)
61+
62+
> Hope that helps!
63+
64+
-----
65+
66+
For the rest of the dump. Go to https://blog.codeship.com/the-definitive-guide-to-ruby-heap-dumps-part-i/ but not the header.
2867

2968
> Manually inspecting this file might be of some interest, but we really need to aggregate information to make use of this data. Before we do that, let’s look at some of the keys in the generated JSON.
3069
> * generation: The garbage collection generation where the object was generated
@@ -35,7 +74,7 @@ Here is a list of questions I have. Feel free to make a PR to answer them.
3574
> * references: The memory addresses of other objects that this object retains
3675
> There are other keys, but that’s enough for now. It’s worth noting that several of these are optional. For example if an object was generated before you started tracing object allocations, it won’t contain generation, file, or line information.
3776
38-
* What is allocated and what is not allocated ([*Not every object requires allocation*](https://youtu.be/gtQmWk8mCRs?list=PLXvaGTBVk36uIVBGKI72vqd9BFcMmPFI7&t=1869))?
77+
* **[Partially answered]**j w What is allocated and what is not allocated ([*Not every object requires allocation*](https://youtu.be/gtQmWk8mCRs?list=PLXvaGTBVk36uIVBGKI72vqd9BFcMmPFI7&t=1869))?
3978

4079
The list is a mix of "types" that may be not clear enough
4180

0 commit comments

Comments
 (0)