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

  • Home
  • SEARCH
  • 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 9016329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:58:12+00:00 2026-06-16T03:58:12+00:00

Seems its easy question, but I am doubt. Will operator delete destroy all Object

  • 0

Seems its easy question, but I am doubt. Will operator delete destroy all Object‘s elements when I call delete list for non empty list created with operator new? Sure it will, but I need confirmation. As you see Object have constructor, but without distributor.

Code:

std::list<Object>* ptr_listObjects = new std::list<Object>();
OtherObject* ptr_null = NULL;
ptr_listObjects->push_back ( Object( ptr_null, 'A') );
ptr_listObjects->push_back ( Object( ptr_null, 'A') );
ptr_listObjects->push_back ( Object( ptr_null, 'A') );
ptr_listObjects->push_back ( Object( ptr_null, 'A') );
ptr_listObjects->push_back ( Object( ptr_null, 'A') );
ptr_listObjects->push_back ( Object( ptr_null, 'A') );
delete ptr_listObjects; // no any possible memory leaks? (Object does not use `new` operator)


class Object
{
public:
    Object( OtherObject* ptr_other, char xxx):
    ptr_OtherObject(ptr_other),
    charflag(xxx)
    {}


    OtherObject* ptr_OtherObject;
    char charflag;
};
  • 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-06-16T03:58:13+00:00Added an answer on June 16, 2026 at 3:58 am

    The std::list destructor will run and so will the destructor of it’s elements. That said, why are you allocating a container dynamically to begin with? You’re making it impossible for the container to manage memory for you. Let it do its job; allocate the list with automatic storage duration.

    As an aside, Object does have a destructor, the compiler generates an empty one for you. There’s nothing to clean up though, so it doesn’t do anything. Also, it is clear from the class design that instances of Object do not own the pointer it takes in its constructor, so make sure to never deallocate it unless you change your design significantly.

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

Sidebar

Related Questions

Sorry if this question seems a bit complex but I think its all related
This question seems easy but for some reason I have trouble finding the answer.
seems like an easy question but I can't get this. I have a property
this is might be a very basic question, but seems like it's not easy
This seems to be an easy question but I can't for the life of
I changed the question as its seems to be a problem with target not
Seems when I make move refactoring all my junit tests lays on its old
This concept seems to trouble me. Why does an NSError object need its pointer
So this is probably a fairly easy question to answer but here goes anyway.
This is similar to a recent question. I will be maintaining sorted a list

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.