mirror of
https://github.com/boostorg/intrusive.git
synced 2025-08-03 22:44:43 +02:00
Fix memory leak
This commit is contained in:
@@ -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
|
||||||
|
Reference in New Issue
Block a user