Skip to content
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:

Clone this wiki locally