> -----Original Message----- > From: Moderated discussion of advanced .NET topics. > [mailto:[EMAIL PROTECTED] On Behalf Of Pinto, Ed > Sent: Freitag, 8. August 2003 03:09 > To: [EMAIL PROTECTED] > > Yes I mean reachable from a root. > > <snip>If it was able to determine whether objects were > reachable without performing a GC, it wouldn't need to do > most of the work involved in performing a GC!</snip> > > Interesting. I thought that the graph calculation was > comparatively less expensive than compacting the memory.
Yes, they are. BUT they are done in the cylce of the GC. They are not tracked when the GC is not running. Otherwise all the ref counting would add up to a lot of work. And introduce other problems. > <snip>Why do you need to know this?</snip> > > I cannot determine the lifetime of the objects I am caching > (otherwise I would make them disposable). Many different > objects may have picked up references to them. The cache will > periodically be passed an object that is a different > instance, but has the same logical identity as an object > already in the cache. If the cached object is reachable from > a root and it is dirty, then the incoming object is > discarded. However, if the cached object is not reachable > from a root, then the incoming object should replace it. Why do you care whether it is rooted? If it is STILL THERE in the cache (not collected) then return the instance you do already have. This makes the object rooted again :-) Works like a charm. You "unique" the object when thre is a cached instance. And this the weak reference tells you. Thomas Tomiczek THONA Software & Consuting Ltd. (Microsoft MVP C#/.NET)