D
Daniel Billingsley
Suppose I have a form FormA, and two objects ObjectB, and ObjectC.
ObjectC has an event SomethingChanged.
FormA has a reference to ObjectC.
FormA also instantiates an ObjectB object, passing it the ObjectC object and
one of its controls. (ObjectB stores those two references.)
ObjectB registers to handle the passed ObjectC's SomethingChanged event and
updates the passed control on FormA when it's fired.
(yes, roll-you-own data binding)
ObjectB doesn't need an explicit method to unhook from ObjectC, does it?
(I've seen code where it implements IDisposable and does it in Dispose.)
My understanding from when I asked this kind of question before was that the
only issue would be if ObjectB outlived ObjectC or FormA, as it would be
holding references to these objects that we really wanted to get collected.
In the arrangement as I described it, where ObjectB is no longer needed when
FormA is closed, I understand that everything will work fine.
Is my thinking right? If so, is there still an advantage to the explicit
unhooking?
ObjectC has an event SomethingChanged.
FormA has a reference to ObjectC.
FormA also instantiates an ObjectB object, passing it the ObjectC object and
one of its controls. (ObjectB stores those two references.)
ObjectB registers to handle the passed ObjectC's SomethingChanged event and
updates the passed control on FormA when it's fired.
(yes, roll-you-own data binding)
ObjectB doesn't need an explicit method to unhook from ObjectC, does it?
(I've seen code where it implements IDisposable and does it in Dispose.)
My understanding from when I asked this kind of question before was that the
only issue would be if ObjectB outlived ObjectC or FormA, as it would be
holding references to these objects that we really wanted to get collected.
In the arrangement as I described it, where ObjectB is no longer needed when
FormA is closed, I understand that everything will work fine.
Is my thinking right? If so, is there still an advantage to the explicit
unhooking?