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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:35:41+00:00 2026-05-26T02:35:41+00:00

I am slightly confused about how memory management works in C++, I understand when

  • 0

I am slightly confused about how memory management works in C++, I understand when you use pointers (new/delete) but I’m lost when it comes to Frame allocation.

Say I have a simple class (Using QT Classes)

class Demo {
    public:
        Demo();
        ~Demo();
        QString AString() const;
        void setAString(const QString &value);
    private:
        QString aString;
};

And I Allocate it using a pointer

Demo *testInst = new Demo();

Now I understand when i call “delete testInst;” That is freed, but I’m confused about the out of scope part on Frame Allocations. Does that mean when I call delete, all those in the class that are not pointers are automatically freed, or do i have to do specific memory management within the deconstructor of the Demo class? Or does it mean if I leave the class those variables are freed?

I’m new to C++ and came from a .NET background so I’m not 100% understanding of manual memory management.

  • 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-26T02:35:41+00:00Added an answer on May 26, 2026 at 2:35 am

    There are two allocation disciplines in C++. Heap and Stack. I’m suspecting that you mean Stack when you write ‘frame’. Sometimes, especially in old C sources, it’s called ‘auto’.

    Demo localDemo;
    

    is how you would use the stack. Before executing the next statement after this, C++ promises to create a temporary object of type Demo and call the no-args constructor. After the last statement in the current {} lexical block that references localDemo, C++ promises to call the destructor and release the storage. The storage is, in fact, part of the stack frame of the procedure or block.

    A related question is a data member of class type. If you write:

    class Proletariat {
       private:
          Demo localDemo;
    };
    

    Then the automatically-generated constructor for Proletariat will call the Demo constructor, and the the destructor will always call the Demo destructor.

    If you have a constructor with args, you write something like:

    class Proletariat {
       private:
          Demo localDemo;
       public:
          Proletariat() : localDemo("omeD") {}
    }
    

    to pass those args.

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

Sidebar

Related Questions

I'm slightly confused about runtime polymorphism. Correct me if I am wrong, but to
I'm slightly confused about what exactly the Model is limited to. I understand that
i am slightly confused about how jquery's Delegate Function works. If I have a
I get a compile error, which I'm slightly confused about. This is on VS2003.
I'm trying out ASP.NET MVC, but, after reading a huge tutorial, I'm slightly confused.
I've just read The Good Parts, and I'm slightly confused about something. Crockford's example
I'm attempting to implement BFS in Python, I understand how the algorithm works but
I am trying add value to a mutlidimensional array but I am slightly confused
I'm just starting out with pointers, and I'm slightly confused. I know & means
I'm slightly confused as to how ARC works, I know there is automatic reference

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.