-
Notifications
You must be signed in to change notification settings - Fork 75
Delegates
fremag edited this page Nov 28, 2016
·
5 revisions
MemoScope can analyze all types inheriting MultiCastDelegate class. Open a dump a file and click on "Delegate Types" command will display statistics about delegates:
- Count: number of type instances
- Total Targets: sum of invocation lists from all type instances
Let's have a look at the file : SimpleEventScript.cs
public override void Run()
{
objects = new List<object>();
for(int i=0; i < N; i++)
{
var obj = new ClassWithEventHandlers();
var firstCallBack = new FirstCallBacks();
var secondCallBack = new SecondCallBacks();
obj.FirstEventHandler += firstCallBack.MyFirstCallBack;
obj.SecondEventHandler += secondCallBack.MySecondCallBack;
if (i >= M)
{
objects.Add(firstCallBack);
}
objects.Add(secondCallBack);
objects.Add(obj);
}
}
}
public class ClassWithEventHandlers
{
public delegate int MyIntDelegate(int x, int y);
public delegate void MyVoidDelegate(string s);
public event MyIntDelegate FirstEventHandler;
public event MyVoidDelegate SecondEventHandler;
}
It will create N ClassWithEventHandlers objects. This class defines two delegate types:
- MyIntDelegate
- MyVoidDelegate
And two events:
- FirstEventHandler
- SecondEventHandler
The code will create N instances of type:
- FirstCallBacks
- SecondCallBacks And will add/subscribe the instances to events in ClassWithEventHandlers instances.
In this picture, we can see the instances of delegate types and the total number of target (method add to the event invocation list)
Double click on a type or select it and click on the "Deletage Instances" command / button to display every instances and its number of targets:
MemoScope: Introduction - Dump a process