Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6888363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:00:20+00:00 2026-05-27T06:00:20+00:00

I think I’m attempting the wrong approach here so please tell me if what

  • 0

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”.

I have an object callled Spawner which spawns KillerObjects every X ms, when I want the KillerObject to be destroyed I call:

void Spawner::RemoveKillerObject(KillerObject* removeThis)
{
    garbageList.push_back(removeThis);
}

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:

 void Spawner::Update(float elapsedTime)
 {
     elapsedSince += elapsedTime;
     if (elapsedSince > spawnRate)
     {
        Spawn();
        elapsedSince = 0;
     }
     for each (KillerObject* removeThis in garbageList)
     {
         spawnedObjects.remove(removeThis);
     }
     garbageList.clear();

     for each (KillerObject* ko in spawnedObjects)
     {
            ko->Update(elapsedTime);
     }
 }

Spawn is simply creating a pointer to a KillerObject and pushes it into the spawnedObject list.

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.

A point in the right direction or any other help is very much appreciated.

Kind regards

Markus

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:00:21+00:00Added an answer on May 27, 2026 at 6:00 am

    I must admit, that I have not completely understood your code, but you probably have a memory leak, i.e. produce more objects new KillerObject() than you delete. You could use a similar statement somewhere to remove the objects that are no longer needed:

    for (std::list<KillerObject*>::iterator it = garbageList.begin(); it != garbageList.end(); ++it) {
      delete (*it);
    }
    garbageList.clear();
    

    or just change:

    void Spawner::RemoveKillerObject(KillerObject* removeThis)
    {
      delete removeThis;
      //garbageList.push_back(removeThis);
      // todo: add code to remove the pointer from the list
      removeThis = NULL;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Think that I have many activities,and all I want is this: I have a
Think at this scenario: I have a c# windows form application. This application was
I think that I am stuck with this particular situation: Here are my tables:
Think: tiling my emacs window with eshells, a la xmonad. Is this possible? I
I think most people know how to do this via the GUI (right click
I think most people here understand the importance of fully automated builds. The problem
I think this is specific to IE 6.0 but... In JavaScript I add a
I think I know how to handle this case, but I just want to
Think of this: A view controller's view is added as subview to another view.
Think Windows Explorer's 'Details' view. I need to output my database to this view.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.