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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:37:11+00:00 2026-05-14T21:37:11+00:00

What potential memory leaks won’t an implicit destructor handle? I know that if you

  • 0

What potential memory leaks won’t an implicit destructor handle? I know that if you have anything stored on the heap it won’t handle it, and if you have a connection to a file or a database, that needs to be handled manually. Is there anything else? What about, say, non-base data types like vectors?

Also, in an explicit destructor, need you destroy non-heap variables which would have been destroyed by the implicit, or are they handled automatically?

Thanks

  • 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-14T21:37:11+00:00Added an answer on May 14, 2026 at 9:37 pm

    What potential memory leaks won’t an implicit destructor handle? I know that if you have anything stored on the heap it won’t handle it, and if you have a connection to a file or a database, that needs to be handled manually. Is there anything else? What about, say, non-base data types like vectors?

    To put it simply, you are correct. The only thing not handled by the implicit destructor is memory allocated in the form of a pointer or another type of resource that needs to be released explicitly.

    With regard to vectors or any other class type objects; all classes have a destructor which takes care of releasing their data. The destructor of an object of this type is called when it goes out of scope. All basic data types like: int, float, double, short, bool etc are released in similar fashion.

    Also, in an explicit destructor, need you destroy non-heap variables which would have been destroyed by the implicit, or are they handled automatically?

    The answer to this is that they are handled automatically, in fact you should never ever try to explicitly call the destructor of an object.

    In an implicit destructor the following occurs:

    • Each of the member variables of the class have their destructors called in turn.

    In an explicit destructor the following occurs:

    • The body of the explicit destructor is executed
    • Each of the member variables of the class have their destructors called in turn.

    So you can see that an explicit destructor is much the same as an implicit one, except that you can take any necessary manual intervention.

    Now as a bit of advice with regard to managing memory allocated objects you should pretty much always use RAII (resource acquisition is initialisation). The crux of this is smart pointers, these are pointers that are deleted correctly when they go out of scope just like non heap allocated objects. Ownership becomes an issue once you start using them but that’s a story for another day. A good place to start with smart pointers is boost::shared_ptr. (btw if you haven’t got on board with boost yet and you write c++ code do yourself a favour…)

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

Sidebar

Related Questions

I know that buffer overruns are one potential hazard to using C-style strings (char
I have a Dictionary<string,int> that has the potential to contain upwards of 10+ million
I'm chasing a couple of potential memory leaks in a Perl code base and
We have a lot of open discussions with potential clients, and they ask frequently
Hy all, I believe that the following piece of code is generating memory leak?
In my code, I have something that looks like this: @implementation MyClass - (id)
The table I'm dealing with it potentially larger than available memory (let's say 10GB)
What are the potential pros and cons of each of these queries given different
FindBugs has found a potential bug in my code. But it is not a
Is this wise, what potential issues could you run into?

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.