How does the Garbage Collector decide when to kill objects held by WeakReferences?

Posted by Kennet Belenky on Stack Overflow See other posts from Stack Overflow or by Kennet Belenky
Published on 2010-04-20T02:29:39Z Indexed on 2010/04/20 2:33 UTC
Read the original article Hit count: 334

I have an object, which I believe is held only by a WeakReference. I've traced its reference holders using SOS and SOSEX, and both confirm that this is the case (I'm not an SOS expert, so I could be wrong on this point).

The standard explanation of WeakReferences is that the GC ignores them when doing its sweeps. Nonetheless, my object survives an invocation to GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced).

Is it possible for an object that is only referenced with a WeakReference to survive that collection? Is there an even more thorough collection that I can force? Or, should I re-visit my belief that the only references to the object are weak?

© Stack Overflow or respective owner

Related posts about garbage-collection

Related posts about weak-references