title: How to handle disposable resources within dictionary
body: <p>We have some data source classes which handle operations on disposable resources, like this:</p>
  
  <pre><code>public class SomeDataStore
  {
      private readonly object dictionaryLock = new object();
  
      private readonly Dictionary&lt;uint, SomeDisposableClass&gt; dataStore = new Dictionary&lt;uint, SomeDisposableClass&gt;();
  
      public bool Remove(uint key)
      {
          bool returnValue = false;
  
          lock (dictionaryLock)
          {
              returnValue = dataStore.Remove(key);
          }
  
          //OR...
  
          lock (dictionaryLock)
          {
              SomeDisposableClass element;
  
              if (dataStore.TryGetValue(key, out element))
              {
                  element.Dispose();
                  returnValue = dataStore.Remove(key);
              }
          }
  
          return returnValue;
      }
  
      public void Clear()
      {
          lock (dictionaryLock)
          {
              dataStore.Clear();
          }
  
          //OR...
  
          lock (dictionaryLock)
          {
              foreach (var value in dataStore.Values)
                  value.Dispose();
  
              dataStore.Clear();
          }
      }
  
      //Some other Datastore access members
  }
  
  public class SomeDisposableClass : IDisposable
  {
      public void Dispose()
      {
          //Dispose resources..
      }
  }
  </code></pre>
  
  <p>Not sure which version should be better and why? Does <code>Dictionary</code>'s <code>Clear</code> or <code>Remove</code> internally handle <code>disposable</code> resource?</p>