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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:34:25+00:00 2026-06-06T06:34:25+00:00

People always talk about how objects created without the new keyword are destroyed when

  • 0

People always talk about how objects created without the new keyword are destroyed when they go out of scope, but when I think about this, it seems like that’s wrong. Perhaps the destructor is called when the variable goes out of scope, but how do we know that it is no longer taking up space in the stack? For example, consider the following:

void DoSomething()
{
  {
    My_Object obj;
    obj.DoSomethingElse();
  }
  AnotherFuncCall();
}

Is it guaranteed that obj will not be saved on the stack when AnotherFuncCall is executed? Because people are always saying it, there must be some truth to what they say, so I assume that the destructor must be called when obj goes out of scope, before AnotherFuncCall. Is that a fair assumption?

  • 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-06T06:34:26+00:00Added an answer on June 6, 2026 at 6:34 am

    You are confusing two different concepts.

    Yes, your object’s destructor will be called when it leaves its enclosing scope. This is guaranteed by the standard.

    No, there is no guarantee that an implementation of the language uses a stack to implement automatic storage (i.e., what you refer to as “stack allocated objects”.)

    Since most compilers use a fixed size stack I’m not even sure what your question is. It is typically implemented as a fixed size memory region where a pointer move is all that is required to “clean up” the stack as that memory will be used again soon enough.

    So, since the memory region used to implement a stack is fixed in size there is no need to set the memory your object took to 0 or something else. It can live there until it is needed again, no harm done.

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

Sidebar

Related Questions

I always hear people talk about DOM this, manipulate the DOM, change the DOM,
I always seen on SyncLock examples people using Private Lock1 As New Object '
Everyone likes to talk about reusability. Where I work, whenever some new idea is
I always see people talking at GoogleIO or WWDC about how drawing the screen(bits/pixels)
I've kind of been confused about properties. Some people say to always use setters
I have always heard people saying bad about using cursors and this is especially
Ok I admit I always see people griping about IE (Internet Explorer xx) and
I always see people mention that Python binding and C Sharp binding etc. when
I always see people in serious projects use :: everywhere, and -> only occasionally
I have always seen people write class.h #ifndef CLASS_H #define CLASS_H //blah blah blah

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.