So is there something I need to do to tell B to undo the
event subscription?
When A is eventually ready for collection the GC won't be
able to reclaim A
because of this reference?
From what you say below eventually there should be a memory
allocation
failure?
Thanks
Rob.
-----Original Message-----
From: Discussion of development on the .NET platform using
any managed
language [mailto OTNET-CL
R DISCUSS.DEVELOP.COM] On Behalf Of Ryan Heath
Sent: Thursday, November 16, 2006 2:01 AM
To: DOTNET-CLR DISCUSS.DEVELOP.COM
Subject: Re: [DOTNET-CLR] Object Lifetimes (GC) Event
Subscriptions
On 11/15/06, Robert Rolls <robertro netspace.net.au> wrote:
> Does A need to keep B around for the lifetime of A or
as B has
> registered for an event will it live for the duration
of A's existence
> (i.e., the object reference is in the delegate call
chain)?
The delegate chain is not implemented as a weakreference
chain, therefor,
the chain MUST keep a *normal* ref to B.
Exactly due to this behaviour, people are *leaking* winforms
instances in
their programs. The instances of winforms (or other
controls) are kept alive
through their event subscribers without notice...
// Ryan
===================================
This list is hosted by DevelopMentorR http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
===================================
This list is hosted by DevelopMentorŪ http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
|