c++ std::map deleting pointers : <p>I will link the classes and output from execution below.</p>

<p>The problem is, the <code>std::map</code> is iterating through and the pointer stored in the second which is of type <code>void*</code> is not deleting from the heap and freeing. The <code>std::map</code> iterated through in the <code>void ShutDown(void);</code> method of the <code>class Engine</code> which is called in the <code>destructor</code> for that class.</p>

<p>I will post the code and output from execution.</p>

<p>Engine header file:</p>

<pre><code>#ifndef _TEST_ENGINE_H_
#define _TEST_ENGINE_H_

#include "test_graphics_system.h"

#include &lt;iostream&gt;
#include &lt;map&gt;

namespace Core {
    enum class EngineStatus {
        Invalid,

        Constructing,
        Setup,

        Running,

        ShutDown,
        Destroying
    };

    class Engine
    {
    public:
        Engine(void);
        ~Engine(void);

        template&lt;class T&gt; T * GetSystem(SystemType systemType)
        {
            if (mSystems[systemType])
            {
                return (T*)mSystems[systemType];
            }
            else
            {
                std::wcout &lt;&lt; "System doe not exist" &lt;&lt; std::endl;
            }
            return nullptr;
        }

        int Run(void);

    private:
        template&lt;class T&gt; void AddSystem(T * system)
        {
            size_t count = mSystems.size();
            auto pair = std::make_pair(system-&gt;GetType(), (T*)system);
            mSystems.insert(pair);

            if (count == mSystems.size())
                std::wcout &lt;&lt; "System failed to be added" &lt;&lt; std::endl;
            else
                std::wcout &lt;&lt; "System added" &lt;&lt; std::endl;
        }

        void Setup(void);
        void ShutDown(void);

        void SetupGraphicsSystem(void);

        static EngineStatus mEngineStatus;

        std::map&lt;SystemType, void*&gt; mSystems;

        bool mRunning;
    };
}

#endif _TEST_ENGINE_H_
</code></pre>

<p>Engine source file:</p>

<pre><code>#include "test_engine.h"

using namespace std;
using namespace Core;

EngineStatus Engine::mEngineStatus = EngineStatus::Invalid;

Engine::Engine(void)
{
    mEngineStatus = EngineStatus::Constructing;

    Setup();
}

Engine::~Engine(void)
{
    mEngineStatus = EngineStatus::Destroying;

    ShutDown();
}

int Engine::Run(void)
{
    mEngineStatus = EngineStatus::Running;

    return 0;
}

void Engine::Setup(void)
{
    mEngineStatus = EngineStatus::Setup;
    SetupGraphicsSystem();
}

void Engine::ShutDown(void)
{
    mEngineStatus = EngineStatus::ShutDown;

    wcout &lt;&lt; endl;
    int count = 0;
    size_t total = mSystems.size();
    for (auto obj : mSystems)
    {
        safe_delete(obj.second);
        wcout &lt;&lt; "\rSystem(s) deleted: " &lt;&lt; ++count &lt;&lt; " of " &lt;&lt; total;
    }
}

void Engine::SetupGraphicsSystem(void)
{
    GraphicsSystem * gs = new GraphicsSystem(mSystems.size(), L"GraphicsSystem01", SystemType::Graphics);
    AddSystem(gs);
}
</code></pre>

<p>Main source file:</p>

<pre><code>#include "safe_del_rel.h"
#include "strings.h"

#include "test_engine.h"

using namespace std;
using namespace Core;

void _DebugMemLeakDetection(void) {
#if defined(_DEBUG) || defined(DEBUG)
    int flag = _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    flag |= _CRTDBG_LEAK_CHECK_DF; // Turn on leak-checking bit
    _CrtSetDbgFlag(flag);
    _CrtSetBreakAlloc(0);
#endif
}

int main(int argv, char argc[])
{
    _DebugMemLeakDetection();

    Engine * eng = new Engine();
    eng-&gt;Run();

    system("pause");
    safe_delete(eng);
    return 0;
}
</code></pre>

<p>Output from last runtime:</p>

<pre><code>'test_engine_console.exe' (Win32): Loaded 'C:\vs_projects\test_engine\x64\Debug\test_engine_console.exe'. Symbols loaded.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\msvcp140d.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\ucrtbased.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\vcruntime140d.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Unloaded 'C:\Windows\System32\vcruntime140d.dll'
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\kernel.appcore.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Cannot find or open the PDB file.
'test_engine_console.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Cannot find or open the PDB file.
The thread 0x4134 has exited with code 0 (0x0).
The thread 0x46ac has exited with code 0 (0x0).
The thread 0x307c has exited with code 0 (0x0).
Detected memory leaks!
Dumping objects -&gt;
{161} normal block at 0x00000293DD5E2680, 48 bytes long.
 Data: &lt;G r a p h i c s &gt; 47 00 72 00 61 00 70 00 68 00 69 00 63 00 73 00 
{160} normal block at 0x00000293DD5E1820, 16 bytes long.
 Data: &lt; R]             &gt; A0 52 5D DD 93 02 00 00 00 00 00 00 00 00 00 00 
Object dump complete.
The program '[12764] test_engine_console.exe' has exited with code 0 (0x0).
</code></pre>

<p>If someone can help plesae do.</p>
