J
joe
Hi,
I have a user control which subscribes to user defined
events fired from a worker thread.
I have a variable, which holds reference of an instance of
this control:
MyClass
{
MyControl m_MyControl;
......
SomeFunction()
{
m_MyControl=new MyControl();
}
}
From time to time I call this function to assign a new
control to m_MyControl and I hope that the old control
will be garbage-collected. But I found that even if I
assign a new instance to m_MyControl, I still get events
received by the control previously assigned to
m_MyControl, which means that the it (the old control) is
still alive . Does that mean that as long as a control (or
any object for that matter) has subscribed but no
unsubscribed for an event it is deemed alive and cant be
GC? They say in the books that unsubscribing is rarely
necessary?
Thanks,
joe
I have a user control which subscribes to user defined
events fired from a worker thread.
I have a variable, which holds reference of an instance of
this control:
MyClass
{
MyControl m_MyControl;
......
SomeFunction()
{
m_MyControl=new MyControl();
}
}
From time to time I call this function to assign a new
control to m_MyControl and I hope that the old control
will be garbage-collected. But I found that even if I
assign a new instance to m_MyControl, I still get events
received by the control previously assigned to
m_MyControl, which means that the it (the old control) is
still alive . Does that mean that as long as a control (or
any object for that matter) has subscribed but no
unsubscribed for an event it is deemed alive and cant be
GC? They say in the books that unsubscribing is rarely
necessary?
Thanks,
joe