Determining if an object has been finalized.

  • Thread starter Thread starter Phil Jones
  • Start date Start date
P

Phil Jones

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
 
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
 
Phil Jones said:
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
 
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).

Not true - you could have a reference to it and you're being finalized
as well.
 
Jon Skeet said:
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
 
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
 
You would have to do this yourself - the runtime does not track instances,
only whether or not the object is reachable or not.
 
Back
Top