C# "shared pointer" for alternative memory management?
<p>I am looking for a way to do this in C#:</p>

<ol>
<li>an Asker object will ask a Giver object for Resource objects.</li>
<li>when asked, Giver will search it's Dictionary for existing matching Resource. If found, it will return the reference of the Resource; otherwise, it will create a the new Resource from database data, save that reference in Dictionary, and finally return the reference.</li>
<li>the Asker may ask for the same Resource more than once, in which case Giver will return the same Resource from the Dictionary the same number of times.</li>
<li><p>the Asker may at any time have no use for a given Resource, in which case, it does nothing further to the Resource.</p></li>
<li><p>Problem: How can Giver detect for any Resource that it is no longer in use and remove it from the Dictionary? Preferably, Giver should do this without Asker's help.</p></li>
</ol>

<p>Is this possible? I can't seem to solve this.</p>

<p>EDIT:
Thanks everyone for the great replies. Especially the WeakReferences. I didn't know they were there. But I have 2 main objectives which I could have specified clearer.</p>

<ol>
<li>Giver should not rely on Asker to get notified.</li>
<li>While a given Resource is in use, <em>all</em> of the references must be pointing to the same Resource so that modification to the Resource is reflected in all places where the same Resource is used.</li>
</ol>

<p>EDIT:
[Removed incorrect code block]</p>
