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 / New Users / December 2004

Tip: Looking for answers? Try searching our database.

Determining if an object has been finalized.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Phil Jones - 03 Dec 2004 03:14 GMT
Is there a way to determine if an object has been finalized?  I figured
you'd ask the GC somehow - but I can't see a method for doing this.

Thanks everyone.
==
Phil
Joyjit Mukherjee - 03 Dec 2004 04:56 GMT
Hi,

After you call GC.Collect(), the GC calls the finalizers for the object.
From this onwards, we can't predict when the object has completed its
finalization process and the GC had reclaimed it because the process is
InDeterministic.

Any other suggestions welcome.

Thanks
Joyjit

> Is there a way to determine if an object has been finalized?  I figured
> you'd ask the GC somehow - but I can't see a method for doing this.
>
> Thanks everyone.
> ==
> Phil
David Browne - 03 Dec 2004 06:00 GMT
> Is there a way to determine if an object has been finalized?  I figured
> you'd ask the GC somehow - but I can't see a method for doing this.

Here's the method to do it:

public static bool HasBeenFinalized(object o)
{
 return false;
}

If you have a reference to the object, then it hasn't been finalized
(unless it's been resurected, but that's another story).

David
Jon Skeet [C# MVP] - 03 Dec 2004 08:53 GMT
> > Is there a way to determine if an object has been finalized?  I figured
> > you'd ask the GC somehow - but I can't see a method for doing this.
[quoted text clipped - 8 lines]
> If you have a reference to the object, then it hasn't been finalized
> (unless it's been resurected, but that's another story).

Not true - you could have a reference to it and you're being finalized
as well.

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

David Browne - 03 Dec 2004 15:16 GMT
>> > Is there a way to determine if an object has been finalized?  I figured
>> > you'd ask the GC somehow - but I can't see a method for doing this.
[quoted text clipped - 11 lines]
> Not true - you could have a reference to it and you're being finalized
> as well.

Aah, which, of course, is probably the only time you would care if another
object has already been finalized.

David
Phil Jones - 05 Dec 2004 02:22 GMT
Very interesting - thanks guys.
Mike Blake-Knox - 05 Dec 2004 16:48 GMT
> Aah, which, of course, is probably the only time you would care if another
> object has already been finalized.

Is there another way to obtain a count of the unfinalized (un garbage
collected would be better) instances of a class? (I've inherited some
software that had put finalizers and destructors in place purely so that
performance monitoring counters could be generated.) I removed this when we
started having memory problems.

Thanks

Mike
David Levine - 05 Dec 2004 23:57 GMT
You would have to do this yourself - the runtime does not track instances,
only whether or not the object is reachable or not.

>> Aah, which, of course, is probably the only time you would care if
>> another
[quoted text clipped - 10 lines]
>
> Mike

Rate this thread:







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.