title: c++ deleting static objects
body: <p>I am just learning C++, and I'm having some trouble with memory leaks. I am using Visual Studio express, and I have enabled the crtdbg commands to dump memory leaks when the program closes. I cannot for the life of me, though, see why this particular line is being marked as a memory leak.</p>
  
  <p>I have a class for Resource, and it contains a <br></p>
  
  <pre><code>static std::unordered_map&lt; std::string, std::unique_ptr &lt; Resource &gt;&gt; RESOURCE_LIBRARY;
  </code></pre>
  
  <p>This contains the definitions of the available resources, and then a factory method makes new resources based on these definitions when new resources are needed.</p>
  
  <p>I then have a method that populates this map like this:<br></p>
  
  <pre><code>std::unique_ptr&lt; Resource &gt; lResource = std::unique_ptr&lt; Resource &gt;(new Resource(0, 0));
  Resource::RESOURCE_LIBRARY["blue"] = std::move(lResource);
  </code></pre>
  
  <p>The problem I am seeing is that these lines to populate the map are the source of the memory allocation that isn't cleared up, according to Visual Studio. I have tried a method to free this like this:</p>
  
  <pre><code>for (auto it = RESOURCE_SOURCE_LIBRARY.begin(); it != RESOURCE_SOURCE_LIBRARY.end(); it++)
  {
      it-&gt;second.reset();
  }
  </code></pre>
  
  <p>but I still get the same messages out. I am sure that I must be missing/misunderstanding something here, so any help would be appreciated.</p>
  
  <p><b>Edit:</b><br>
  Here's an example:</p>
  
  <pre><code>#define _CRTDBG_MAP_ALLOC
  
  #include &lt;crtdbg.h&gt;
  #include &lt;string&gt;
  #include &lt;unordered_map&gt;
  
  class Resource
  {
  public:
      Resource(){};
      static std::unordered_map&lt;std::string, Resource&gt; LIBRARY;
  };
  
  std::unordered_map&lt;std::string, Resource&gt; Resource::LIBRARY;
  
  int main()
  {
      Resource lResource;
      Resource::LIBRARY["first"] = lResource;
      Resource::LIBRARY.clear();
  
      _CrtDumpMemoryLeaks();
  }
  </code></pre>
  
  <p>This reports that the memory is allocated in the line</p>
  
  <pre><code>Resource::LIBRARY["first"] = lResource;
  </code></pre>