Joel Mueller wrote:

> That's the problem, though, isn't it? Every time a GC runs, and you
> don't know when that is, your entire cache is cleared out, except for
> the objects that you might happen to actually be using at the time of
> the GC. Wouldn't it be better to retain the items that were used
> most-recently, on the theory that they are more likely to be needed
> frequently, and only remove those items if you still don't have enough
> memory after removing the infrequently-used items?

If that's the better case in your scenario, then the GC can't help you.
You'll have to do it yourself. As to the motivation, I couldn't say for
sure, but I'll bet that keeping that kind of "bookkeeping" on objects is
considered excessive overhead for them. From the point of view of a garbage
collector, if something is unreachable, then it doesn't matter if it was
used 10ms again or 10h ago. It can't be reached. The "weak reference"
feature doesn't change this fundamental GC assumption.

> It just seems that if your whole cache (aside from any objects actively
> being used) goes away on every GC, then it's better than no cache at
> all, but not nearly as good as something more intelligent.

Well, that's a question only you can answer. :) There's nothing in v1 of the
platform to do anything more intelligent, but perhaps v2 will address these
concerns. It would seem useful to me, although there is a question of
performance impact. Maybe you could write up a request for a research grant
from MS Research and do it yourself for the v2 platform. :)

Brad

--
Read my web log at http://www.quality.nu/dotnetguy/

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to