Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / November 2003

Tip: Looking for answers? Try searching our database.

WeakReference isalive not working as expected

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ORi - 11 Nov 2003 10:51 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.