Professional Documents
Culture Documents
Last time I talked about the dominator tree and how it can be used to find the biggest objects in your heap easily. So what exactly is the dominator tree?
Dominators
An object A dominates on an object B if all the paths to object B pass through object A. Remember that the Garbage Collector removes all objects that are not referenced anymore. If A dominates B and A could be removed from memory, that means that there's no path anymore that leads to B. B is therefore unreachable and would be reclaimed by the Garbage Collector. One could also say that A is the single object that is responsible for B still being there!
2. Note that the dominator relationship is transitive;C dominates E which dominates G therefore C also dominates G.
Because of the transitivity of "dominated", the retained size of a parent object within the dominator tree is always greater than the sum of it's child objects. To get the biggest objects we just need to sort the second level of the dominator tree (the first level is the "virtual" root object) by retained size. Now if you are looking to find a memory leak, and you have no a priori knowledge that could help you, the typical approach is to run a test that reproduces the leak, and then try to somehow figure out what is leaking.