puzzlecracker <(E-Mail Removed)> wrote:
> A cut-and-paste from the Jon's book, with a question to follow:
>
> Utter garbage! (Or not, as the case may be=3F)=3FIt=3Fs worth being aware
> that a
> delegate instance will prevent its target from being garbage
> collected, if
> the delegate instance itself can=3Ft be collected. This can result in
> apparent
> memory leaks, particularly when a =3Fshort-lived=3F object subscribes to
> an event in a =3Flong-lived=3F object, using itself as the target. The
> long-lived
> object indirectly holds a reference to the short-lived one, prolonging
> its lifetime
>
> 1) what does target refer to (delegate instance will prevent its
> target from being garbage)?
The instance (or rather, the reference to the instance) that the action
will be called on. It's defined in the previous paragraph
So for example, if I do:
EventHandler x = someObject.SaveDocument;
then the value of "someObject" is the target. When the delegate is
invoked, it's like calling someObject.SaveDocument().
--
Jon Skeet - <(E-Mail Removed)>
Web site:
http://www.pobox.com/~skeet
Blog:
http://www.msmvps.com/jon.skeet
C# in Depth:
http://csharpindepth.com