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 7596737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:59:25+00:00 2026-05-30T21:59:25+00:00

I have a class with a list of pointers to objects of that same

  • 0

I have a class with a list of pointers to objects of that same class as an attribute (Children). The problem I have is that when I create an object of that class, add children to it and then try to delete it, it doesn’t really free the memory (judging by the System Monitor). I’m using Ubuntu with g++.

The next code illustrates well my problem. It creates an object, adds ten million children to it and then deletes it. The memory usage goes up from 1.1 to 1.7 gb as I execute the program and It gets stuck there even after the object gets deleted.

¿Does anyone have any idea of what’s happening?

Thanks a lot.

class UDVertex
{
  public:
   int ID;
   list<UDVertex *> Children;
};

void GetChildren(UDVertex * rootVT);

int main()
{
    UDVertex * MyVertex;

    MyVertex = new UDVertex;
    MyVertex -> ID = 0;

    GetChildren(MyVertex);

    while( ! MyVertex -> Children . empty() )
    {
         delete MyVertex -> Children . front();

         MyVertex -> Children . pop_front();
    }

    delete MyVertex;

    std::cout << "Press enter to continue...";
    std::cin.get(); 

    return 0;
}

void GetChildren(UDVertex * rootVT)
{
    UDVertex * Child;
    int i;

    for (i = 0; i < 10000000; i++)
    {
        Child = new UDVertex;
        Child -> ID = i + 1;

        rootVT -> Children . push_back ( Child ) ;

    }   

}
  • 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-30T21:59:27+00:00Added an answer on May 30, 2026 at 9:59 pm

    The problem is your method of measuring the memory.
    The “System Monitor” moniters memory allocated to a processes (which is done in huge chunks).

    Within the processes memory is allocated/reclaimed (after new/delete) by the runtime library; which tracks created and deleted of objects (which are usually tiny in comparison to the pages allocated to the processes). The “System Monitor” does not let you know how much of the memory is currently being actively used by the application (your part of the app) and how much the runtime is holding onto.

    A simple test would be to try allocating the objects again (allocate all memory (check-size) release all memory (check-size) allocate all memory (check-size)).

    If the memory usage stays about the same size (at each check-size) you know that the deleted objects were given back to the runtime and have now been re-acquired by the application without the processes having to ask the OS for another huge chunk.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of class items List<MyClass> I have a seperate object that
I have a mother class that stores the pointers to some objects in a
I have a list of pointers to SomeClass objects in a Main class. Whilst
I have class A and list of A objects. A has a function f
I have class method that returns a list of employees that I can iterate
I have a class that wraps List<> I have GetValue by index method: public
I have code that looks like this: template<class T> class list { public: class
I have an object that contains, as part of its data, a linked list.
I have a list of pointers to objects. These objects have nothing in common
In my class I have two private members: std::list<MyObject> objects; MyObject *selecteObj; When an

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.