Re: About Memory Leaks


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]

Posted by John Kugelman on April 18, 2001 at 00:25:20:

In Reply to: About Memory Leaks posted by Anthony on April 17, 2001 at 17:52:37:

Anthony wrote:

Ok, you dynamically allocate a creature in the Manager class (based on a create command), and insert it into the list through a member function in the Ecosystem class. How would you prevent a memory leak when the creature dies? Look at my situation:

What is happening in my case is that I'm searching through my list of creature pointers until I find the right creature to "make die." Then I get that element and assign a Creature pointer to it, and try to delete it there. But I get a Debug Assertion Error. If I can't delete it through access in the list, how will I prevent a memory leak?

You're right, it's kind of tricky. You can't just kill the creature straight away since you're in the middle of one of its functions. My idea is to do a delayed solution; tell the manager/ecosystem that the creature has died, and leave it at that as far as the creatures are concerned.

Of course the problem is the manager/ecosystem can't just delete the creature immediately since actions pertaining to it are still being processed. So just keep track of the fact and do it later when it's more prudent, like at the end of the tick.




Follow Ups:



Post a Followup

Name:
E-Mail:

Subject:

Comments:

Optional Link URL:
Link Title:
Optional Image URL:


[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]