mirror of
https://github.com/boostorg/intrusive.git
synced 2025-08-03 06:24:44 +02:00
Fix memory leak
This commit is contained in:
@@ -27,7 +27,15 @@ class some_entity : public entity
|
||||
{/**/};
|
||||
|
||||
//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
|
||||
entity_list global_list;
|
||||
@@ -40,14 +48,6 @@ entity::~entity()
|
||||
void insert_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()
|
||||
{
|
||||
//Insert some new entities
|
||||
|
Reference in New Issue
Block a user