dart-sdk/docs/Heap-snapshots.md
Devon Carew 2837647bea [wiki] move the https://github.com/dart-lang/sdk/wiki to the docs/ dir
Change-Id: I28db796fadcc111d97d3589bf3988ea0bbb8e18a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366682
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Devon Carew <devoncarew@google.com>
2024-05-16 18:19:40 +00:00

2.6 KiB

Important

This page was copied from https://github.com/dart-lang/sdk/wiki and needs review. Please contribute changes to bring it up-to-date - removing this header - or send a CL to delete the file.


The VM service protocol provides access to heap snapshots, a description of all the objects and references in the heap at some point in time. Tools such as Observatory provide analysis and visualization of these snapshots to help developers understand the memory usage of their applications.

Concepts

class R {
  var field1;
  var field2;
}
class A {
  var field1;
  var field2;
}
class B {
  var field1;
  var field2;
}
class C {
  var field1;
  var field2;
}
class D {
  var field1;
  var field2;
  var field3;
}
class E {
  var field1;
  var field2;
}
class F {
  var field1;
  var field2;
}
class G {
  var field1;
  var field2;
}

var root;

main() {
    var r = new R();
    var a = new A();
    var b = new B();
    var c = new C();
    var d = new D();
    var e = new E();
    var f = new F();
    var g = new G();
    r.field1 = a;
    r.field2 = b;
    a.field1 = c;
    b.field1 = c;
    b.field2 = d;
    c.field1 = d;
    d.field1 = b;
    d.field2 = e;
    d.field3 = f;
    e.field1 = g;
    f.field1 = g;
    root = r;
}

Successors

The successors of an object are the objects it directly references, such as through an instance variable or an array element.

Graph theory successors Observatory successors

Predecessors

The predecessors of an object are the objects that directly reference it.

Graph theory predecessors Observatory predecessors

Dominators

In a heap dominator tree, an object X is a parent of object Y if every path from the root to Y goes through X. This allows you to find "choke points" that are holding onto a lot of memory. If an object becomes garbage, all its children in the dominator tree become garbage as well.

Graph theory dominators Observatory dominators

Owners

An object X is said to "own" object Y if X is the only object that references Y, or X owns the only object that references Y. In particular, objects "own" the space of any unshared lists or maps they reference.

Graph theory owners

Advice