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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:17:10+00:00 2026-06-11T16:17:10+00:00

Suppose: struct Foo { int _b; std::string _name; }; class Bar { public: vector<Foo>hold;

  • 0

Suppose:

struct Foo
{
    int _b;
    std::string _name;
};

class Bar
{
public:
    vector<Foo>hold;
};

If a call to hold.clear() isn’t done on the destructor, does it means a memory leak?
I’m talking about objects, not pointer, because as far as I know push_back creates a copy of the original object;

  • 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-11T16:17:11+00:00Added an answer on June 11, 2026 at 4:17 pm

    When an object is destroyed, so is all its members. So the (automatically generated) destructor of Bar will call the destructor of its hold member, which is going to call the destructors of its elements.

    In summary: everything is destroyed automatically. This is a guarantee in C++: if you are manipulating objects by value, you have the guarantee that they are going to be destroyed when they get out of scope. The only thing you have to destroy explicitly are the objects that have been allocated on the heap (i.e. using new).

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

Sidebar

Related Questions

Suppose I have: struct Foo: public Bar { .... } Foo introduces no new
Suppose I have a struct containing a std::string, like this: struct userdata{ int uid;
Suppose I have such a struct: struct Foo { const int bar; const char
I'm using LLVM-clang on Linux. Suppose in foo.cpp I have: struct Foo { int
Suppose I have: struct Magic { Magic(Foo* foo); Magic(Bar* bar); }; Is there a
Suppose I have the following: struct Person { std::string mName; Birthday mBirthday; }; using
Suppose: struct A { virtual int foo(const A& a) const { return 1; }
Suppose some type Foo has an overloaded operator-> that returns a Bar* : struct
Suppose I'm given a struct of arrays, e.g.: s = foo: [3x3 double] bar:
Suppose I have some simple struct like this: public struct WeightedInt { public int

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.