Hello,
I'm having a problem with a weakreference. The situation is that I
have some classes in my application that act as a target for a
weakreference collection contained in a Singleton instance of another
application class. This library application is accessed either by a
web application or by a Winforms one, and I used events in my
singleton class where everyone subscribed in order to receive some
notifications. I realized that events where considered strong
references and all my subscribed objects remained in memory even when
the client who instantiated them had disappeared, that's why I changed
it to a weakreference collection to store all the notification
targets. Now, it seems I'm having the oppossite problem, after
registering some classes to the weakreference collection as targets,
sometimes it says that some of the weakreferences aren't alive even
when the current client has an active instance of the target class of
the weakreference. This is quite frustrating and it can be hardly
reproduced by debugging the application as sometimes if I debug the
application step by step it doesn't happen, but it always happen when
I run it without debugging.
Could somebody know any possible reason for this behaviour? Is there
any way in which a weakreference can become invalid (isalive=false,
target=null) although the target instance is still active? I've been
searching a lot but I can't find any clue, any help will be
appreciated !
Thx in advance,
ori
Jennifer Hamilton [MSFT] - 24 Nov 2003 17:07 GMT
That should never happen with long weak refs. Are you possibly using a
short reference and the object is being resurrected by some finalizer?
For more information, MSDN has a great article on weak references
generally, from Jeff Richter at
http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx.
Jennifer Hamilton
CLR Base Services Development Team

Signature
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.