Fix memory leak

This commit is contained in:
Ion Gaztañaga
2015-04-16 23:25:03 +02:00
parent bb94b03dca
commit 9ddcfa8e7d

View File

@@ -27,7 +27,15 @@ class some_entity : public entity
{/**/}; {/**/};
//Definition of the intrusive list //Definition of the intrusive list
typedef list<entity> entity_list; struct entity_list : list<entity>
{
~entity_list()
{
// entity's destructor removes itself from the global list implicitly
while (!this->empty())
delete &this->front();
}
};
//A global list //A global list
entity_list global_list; entity_list global_list;
@@ -40,14 +48,6 @@ entity::~entity()
void insert_some_entity() void insert_some_entity()
{ global_list.push_back (*new some_entity(/*...*/)); } { global_list.push_back (*new some_entity(/*...*/)); }
//Function to clear an entity from the intrusive global list
void clear_list ()
{
// entity's destructor removes itself from the global list implicitly
while (!global_list.empty())
delete &global_list.front();
}
int main() int main()
{ {
//Insert some new entities //Insert some new entities