java - YourKit - The retained size of an object doesn't equal the retained size of all the objects referred by it -


the retained size of object doesn't equal retained size of objects referred it.

here happening:

  1. using yourkit capture memory snapshot.
  2. click on object & show instances class type
  3. let's instance's retained memory bytes (600mb)
  4. expand , sum retained size underlying instances let's sum b (300mb)

a >> b

let me give example.

first of all, need understand retained size is. official documentation:

retained size of object shallow size plus shallow sizes of objects accessible, directly or indirectly, object. in other words, retained size represents amount of memory freed garbage collector when object collected.

in simple retained size of object indeed sum of objects referred it. in picture below retained size of obj1 sum of obj1 shallow size, , obj2 , obj3 retained size: simple case

this not case in more complicated referencing models. if obj6 starts referencing obj5, obj5 not accessible obj2. retained size of obj2 include obj4, , exclude obj5. retained size of obj1 not sum of obj2 , obj3 retained size of obj1 stay same. if garbage collector frees obj1, it'll free whole references graph of size 41. however, if garbage collector frees obj2, not free obj5, because still referenced obj6.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -