hi all, for debugging purpose i want know if an object is already referenced by same other objects.
what i want to do is samething as
void Checks(object o) { WeakReference wr = new WeakReference(o); o = null;
bool b = GCHelper.CanBeCollectedByGC(o.Target); //Log }
korkless
A WeakReference is specifically designed to deal with this. Its IsAlive property tells you if the object still exists. If it no longer exists, it is not referenced by anybody. Why doesn't it suit you? Hans Passant.
Marked As Answer bykorklessFriday, September 11, 2009 12:32 PM
nobugz
Hi, You need to implement the singleton patteron for this
i don't need a singleton, in same place of my application i want know if an object out of that method can be garbaged by GC or if there's same bug and it's already referenced by same other places
korkless
A WeakReference is specifically designed to deal with this. Its IsAlive property tells you if the object still exists. If it no longer exists, it is not referenced by anybody. Why doesn't it suit you? Hans Passant.
Marked As Answer bykorklessFriday, September 11, 2009 12:32 PM
nobugz
yeah, you are right :), isalive tell if the object has been already collected but i want check if the object can be collected so i wrongly discard it, if i call gc.collect before checks isAlive, it works perfectly for what i want, thanks