A
almurph
Hi,
I'm wondering could anyone explain what a weak reference is to me in
C# or perhaps more importantly why it is used.
I ask as I'm reading about an algorithm in the book "C# Cookbook" by
Stephen Teilhet & Jay Hilyard about a light-weight cache. There is a
piece of code that I don't understand, here it is:
*** CODE BEGIN ***
public void AddObj(object key, SomeComplexObj item)
{
Weakreference WR = new WeakReference(item, false);
if(cache.ContainsKey(key))
{
cache[key] = WR;
}
else
{
cache.Add(key, WR);
}
}
*** CODE END ***
I understand most of the algorithm, but i dont understand why the
author is using WeakReference, I dont see the advantage. Can anyone
help me please? Any comments/suggestions/explanations much
appreciated.
Thank you,
Al.
I'm wondering could anyone explain what a weak reference is to me in
C# or perhaps more importantly why it is used.
I ask as I'm reading about an algorithm in the book "C# Cookbook" by
Stephen Teilhet & Jay Hilyard about a light-weight cache. There is a
piece of code that I don't understand, here it is:
*** CODE BEGIN ***
public void AddObj(object key, SomeComplexObj item)
{
Weakreference WR = new WeakReference(item, false);
if(cache.ContainsKey(key))
{
cache[key] = WR;
}
else
{
cache.Add(key, WR);
}
}
*** CODE END ***
I understand most of the algorithm, but i dont understand why the
author is using WeakReference, I dont see the advantage. Can anyone
help me please? Any comments/suggestions/explanations much
appreciated.
Thank you,
Al.