title: Attempting to remove pointers in a list causes constant memory usage growth
body: <p>I think I'm attempting the wrong approach here so please tell me if what I'm trying to achieve won't work with this "technique".</p>
  
  <p>I have an object callled Spawner which spawns KillerObjects every X ms, when I want the KillerObject to be destroyed I call:</p>
  
  <pre><code>void Spawner::RemoveKillerObject(KillerObject* removeThis)
  {
      garbageList.push_back(removeThis);
  }
  </code></pre>
  
  <p>Then everytime the Spawner is updated it will loop through the garbageList to remove every object that has been pushed into the garbage list, like this:</p>
  
  <pre><code> void Spawner::Update(float elapsedTime)
   {
       elapsedSince += elapsedTime;
       if (elapsedSince &gt; spawnRate)
       {
          Spawn();
          elapsedSince = 0;
       }
       for each (KillerObject* removeThis in garbageList)
       {
           spawnedObjects.remove(removeThis);
       }
       garbageList.clear();
  
       for each (KillerObject* ko in spawnedObjects)
       {
              ko-&gt;Update(elapsedTime);
       }
   }
  </code></pre>
  
  <p>Spawn is simply creating a pointer to a KillerObject and pushes it into the spawnedObject list.</p>
  
  <p>The objects are "deleted" in the game as in I can't collide with them and they won't be drawn.
  But this causes my memory usage to continuously grow, I know this is the cause because if I remove this code the memory usage is stable.</p>
  
  <p>A point in the right direction or any other help is very much appreciated.</p>
  
  <p>Kind regards</p>
  
  <p>Markus</p>