-
Notifications
You must be signed in to change notification settings - Fork 75
Referers
fremag edited this page Nov 27, 2016
·
10 revisions
This module analyzes how some instances are refered: for a given set of instances, it will check all instances referencing them and do some stats about their type.
Note: this module is quite complex and hard to explain so do not hesitate to ask question with an Issue.
Let's have a look a this code: RefererScript.cs in MemoDummy
private List<object> objectsList;
private object[] objectsArray;
private HashSet<object> objectsSet;
public int NbObjects { get; set; } = 1000;
public override void Run()
{
objectsList = new List<object>();
objectsArray = new object[NbObjects];
objectsSet = new HashSet<object>();
for(int i=0; i < NbObjects; i++)
{
var o = new ComplexObject();
switch (i%3) {
case 0:
objectsList.Add(o);
break;
case 1:
objectsArray[i / 3] = o;
break;
case 2:
objectsSet.Add(o);
break;
}
}
This piece of code will create NbObjects (=1000) instances of type ComplexObject, store one third of them in a List, one third in an Array and the rest in a HashSet.
This information is displayed in MemoScope:
Let's have a look at the result:
- #1: there are 1000 instances of type: ComplexObject
- #2: there are 9 instances of type Object[] (array of object) referencing 667 instances of the previous line (1000) = 66.7 % of them. The "[ x ]" in the field column means that all ComplexObjects are members of the array but not with teh same index.
- #3: there is one instance of type List referencing one of the 9 instances of type Object[]. 1 on 9 = 11.11 %. This array is referenced in a field name "_items" (you can look at the source code of List to see that items are stored in a field name _items of type array of T[])
- #4: one of the 9 (=11.11%) instances of Object[] is referenced by one instance of RefererScript. Look at the code, this is the instance defined by:
private object[] objectsArray;
- #5: let's go back one level up in the tree. This line means that 333 ComplexObject instances are referenced by 7 arrays of type HashSet.Slot[]
- #6: one instance of type HashSet.Slot[] is referenced by one HashSet instance in its filed "m_slots".
- #7: the insance of type HashSet from previous level in the tree is referenced by one instance of type RefererScript and it's the one defined by line:
private HashSet<object> objectsSet;
MemoScope: Introduction - Dump a process