S
Sebastiaan Olijerhoek
When an eventhandler is created to an object A that stays in use longer than
the object B that implements the eventhandler then the object B is not
release from memory before you remove the eventhandler manually (in a
Dispose method for instance). See code below.
Is this correct?
Are there any tips regards this?
Consider the following code:
class B
{
B()
{
System.Windows.Forms.Application.Idle += new
System.EventHandler(OnApplicationIdle);
}
void OnApplicationIdle(object sender, System.EventArgs e)
{
System.Diagnostics.Trace.Writeln("B.OnApplicationIdle");
}
}
class Form1 : System.Windows.Forms.Form
{
Form1()
{
// Creating an object
B temp = new B();
// Releasing object??
temp = null;
System.GC.Collect();
}
static void Main()
{
Application.Run(new Form1();
}
}
the object B that implements the eventhandler then the object B is not
release from memory before you remove the eventhandler manually (in a
Dispose method for instance). See code below.
Is this correct?
Are there any tips regards this?
Consider the following code:
class B
{
B()
{
System.Windows.Forms.Application.Idle += new
System.EventHandler(OnApplicationIdle);
}
void OnApplicationIdle(object sender, System.EventArgs e)
{
System.Diagnostics.Trace.Writeln("B.OnApplicationIdle");
}
}
class Form1 : System.Windows.Forms.Form
{
Form1()
{
// Creating an object
B temp = new B();
// Releasing object??
temp = null;
System.GC.Collect();
}
static void Main()
{
Application.Run(new Form1();
}
}