title: How to interpret or narrow down the cause of a memory leak in this visual leak detector output?
body: <p>How do I narrow down the cause to find the reason for the memory leak reported in this Visual Leak Detector output? </p>
  
  <p>The question is not to debug this particular code for me, but how to approach problems like this in general. Visual Leak Detector reports many leaks and questions like this are quite frequent here on SO therefore I hope for an answer which is less specific but more general such that it is not only help in this particular case but more for others as well.</p>
  
  <pre><code>---------- Block 305 at 0x00000000FCBFBBB0: 64 bytes ----------
    Leak Hash: 0x7DAD966C, Count: 1, Total 64 bytes
    Call Stack (TID 11728):
    ucrtbased.dll!malloc()
  e:\programme (x86)\microsoft visual studio 14.0\vc\include\xmemory0 (901): Shady.exe!std::_Wrap_alloc&lt;std::allocator&lt;std::_List_node&lt;std::pair&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; const ,std::unique_ptr&lt;Texture,std::default_delete&lt;Texture&gt; &gt; &gt;,void * __ptr64&gt; &gt; &gt;::allocate()
  e:\programme (x86)\microsoft visual studio 14.0\vc\include\list (730): Shady.exe!std::_List_alloc&lt;std::_List_base_types&lt;std::pair&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; const ,std::unique_ptr&lt;Texture,std::default_delete&lt;Texture&gt; &gt; &gt;,std::allocator&lt;std::pair&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,st() + 0x19 bytes
  e:\programme (x86)\microsoft visual studio 14.0\vc\include\list (716): Shady.exe!std::_List_alloc&lt;std::_List_base_types&lt;std::pair&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; const ,std::unique_ptr&lt;Texture,std::default_delete&lt;Texture&gt; &gt; &gt;,std::allocator&lt;std::pair&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,st()
  e:\programme (x86)\microsoft visual studio 14.0\vc\include\list (631): Shady.exe!std::_List_alloc&lt;std::_List_base_types&lt;std::pair&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; const ,std::unique_ptr&lt;Texture,std::default_delete&lt;Texture&gt; &gt; &gt;,std::allocator&lt;std::pair&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,st() + 0xC bytes
  e:\programme (x86)\microsoft visual studio 14.0\vc\include\list (818): Shady.exe!std::_List_buy&lt;std::pair&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; const ,std::unique_ptr&lt;Texture,std::default_delete&lt;Texture&gt; &gt; &gt;,std::allocator&lt;std::pair&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; con()
  e:\programme (x86)\microsoft visual studio 14.0\vc\include\list (896): Shady.exe!std::list&lt;std::pair&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; const ,std::unique_ptr&lt;Texture,std::default_delete&lt;Texture&gt; &gt; &gt;,std::allocator&lt;std::pair&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; const ,s()
  e:\programme (x86)\microsoft visual studio 14.0\vc\include\xhash (197): Shady.exe!std::_Hash&lt;std::_Umap_traits&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;,std::unique_ptr&lt;Texture,std::default_delete&lt;Texture&gt; &gt;,std::_Uhash_compare&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;,std::hash&lt;std() + 0x1A bytes
  e:\programme (x86)\microsoft visual studio 14.0\vc\include\unordered_map (119): Shady.exe!std::unordered_map&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt;,std::unique_ptr&lt;Texture,std::default_delete&lt;Texture&gt; &gt;,std::hash&lt;std::basic_string&lt;char,std::char_traits&lt;char&gt;,std::allocator&lt;char&gt; &gt; &gt;,std::equal_to&lt;std::basic_string()
  e:\repositories\shady\src\texture\texturemanager.h (39): Shady.exe!TextureManager::TextureManager() + 0x44 bytes
  e:\repositories\shady\src\engine.h (53): Shady.exe!Engine::Engine() + 0x65 bytes
  e:\repositories\shady\src\engine.cpp (97): Shady.exe!main() + 0x1D bytes
  f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (75): Shady.exe!invoke_main()
  f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (264): Shady.exe!__scrt_common_main_seh() + 0x5 bytes
  f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl (309): Shady.exe!__scrt_common_main()
  f:\dd\vctools\crt\vcstartup\src\startup\exe_main.cpp (17): Shady.exe!mainCRTStartup()
  KERNEL32.DLL!BaseThreadInitThunk() + 0x22 bytes
  ntdll.dll!RtlUserThreadStart() + 0x34 bytes
    Data:
  B0 BB BF FC    B4 01 00 00    B0 BB BF FC    B4 01 00 00     ........ ........
  CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
  CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
  CD CD CD CD    CD CD CD CD    CD CD CD CD    CD CD CD CD     ........ ........
  </code></pre>
  
  <p><code>engine.cpp 97</code> is <code>Engine engine = Engine();</code> which constructs an object of this class</p>
  
  <pre><code>class Engine{
      Engine() : _logger("Engine"){}
      TextureManager _textureManager;
      Logger mutable _logger;
  };
  </code></pre>
  
  <p>while <code>texturemanager.h 39</code> is <code>TextureManager() :_logger("TextureManager"){};</code> of this class:</p>
  
  <pre><code>class TextureManager{
  TextureManager() :_logger("TextureManager"){};
  ~TextureManager() {
      for (const auto&amp; kv : _textures) {
          GLuint h = kv.second-&gt;getTextureHandle();
          glDeleteTextures(1, &amp;h);
      }
  }
  std::unordered_map&lt;std::string, std::unique_ptr&lt;Texture&gt;&gt; _textures;
  Logger mutable _logger;
  };
  </code></pre>
  
  <p>Did I understand the output correctly that the unordered_map causes the leak? There is no direct allocation with <code>new</code> or <code>malloc</code> involved in this code as I try to completly move to <code>shared</code> and <code>unique pointers</code>. Could the string passed to the constructors and reused and stored in the classes the problem? From what I read std::string does manage its memory itself.</p>