tag:blogger.com,1999:blog-1688176320920284646.post36096664369580835..comments2023-12-20T10:24:23.540+00:00Comments on A day in the life of...: WeakReference woes!Unknownnoreply@blogger.comBlogger2125tag:blogger.com,1999:blog-1688176320920284646.post-84826584229640042902009-04-01T17:47:00.000+01:002009-04-01T17:47:00.000+01:00I am not saying it is hard to use once you know ab...I am not saying it is hard to use once you know about it, I am just saying that it's an easy trap to fall into so I blogged about it.<BR/><BR/>As for removing IsAlive, I think people would just write code like this anyway so there's no point.<BR/><BR/>if (weakRef.Target != null)<BR/> (weakRef.Target as X).DoSomething();Peter Leslie Morrishttps://www.blogger.com/profile/09377536995235480828noreply@blogger.comtag:blogger.com,1999:blog-1688176320920284646.post-27022453035562044172009-04-01T17:14:00.000+01:002009-04-01T17:14:00.000+01:00The MSDN documentation clearly explains this probl...The <A HREF="http://msdn.microsoft.com/en-us/library/system.weakreference.isalive.aspx" REL="nofollow">MSDN documentation</A> clearly explains this problem with IsAlive: "using this property is not recommended unless you are testing only for a false return value".<BR/><BR/>As this suggests, IsAlive is useful for finding dead references, e.g. if you have a dictionary of weak references, you can go through and easily identify the dead references to be removed using the IsAlive property.Andyhttps://www.blogger.com/profile/16478337776529279382noreply@blogger.com