-
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.
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:
# | Type Name | # Instances | # References | References % | Field Name |
---|---|---|---|---|---|
1 | MemoDummy.ComplexObject | 1,000 | 0 | 0.00 % | |
2 | System.Object[] | 9 | 667 | 66.70 % | [ x ] |
3 | System.Collections.Generic.List< System.Object> | 1 | 1 | 11.11 % | _items |
4 | MemoDummy.RefererScript | 1 | 1 | 11.11 % | objectsArray |
5 | System.Collections.Generic.HashSet+Slot< System.Object> [ ] | 7 | 333 | 33.30 % | [ x ] |
6 | System.Collections.Generic.HashSet< System.Object> | 1 | 1 | 14.29 % | m_slots |
7 | MemoDummy.RefererScript | 1 | 1 | 100.00 % | objectsSet |
- Line #1: there are 1000 instances of type: ComplexObject
- Line #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.
- Line #3: There is one instance of type List referencing one of the 9 instances of type Object[]. 1 on 9 = 11.11 %.
MemoScope: Introduction - Dump a process