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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:19:51+00:00 2026-06-15T11:19:51+00:00

Recently I learned that using smart ptr could make our work easier. I tried

  • 0

Recently I learned that using smart ptr could make our work easier. I tried to add boost::scoped_ptr into my code. However, I’m quite not sure whether I should delete a pointer to class. Here is my code:

    class onTimeStepOp : public QWidget
    {
        public:
            //some function here
            ~onTimeStepOp(){delete xr;}
        private:
            xmlReader *xr;
            //others.
    };

for(int i = m; i >= 1; --i) {
    boost::scoped_ptr<onTimeStepOp> otso(new onTimeStepOp(
                                             QString::number(currentFrameNum - i),  
                                             QString::number(currentFrameNum)   
                                             ));  
    //do something here.
}

It seems that the otso will call its destructor at the end of the scope. So I added the destructor into the class. The program crashed after running. However, without the destructor, it seems that the program is leaking memory with the help of Valgrind. I’m quite confused about that. Does it mean that deletion is unnecessary(May be deleting a freed memory for the second time? I’m not sure about that) when using smart pointer and how does the code crash?

  • 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-15T11:19:52+00:00Added an answer on June 15, 2026 at 11:19 am

    A smart pointer will only invoke the destructor of the instance it’s holding. If that instance happens to have other dynamically allocated members, those are not cleaned up automatically (unless you hold them in smart pointers too!)

    So in your case, hold the member in a smart pointer too (boost::scoped_ptr or boost::shared_ptr etc.)

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

Sidebar

Related Questions

I recently learned about using C# extension methods to make calling events easier and
I recently learned that I could do this: height()+100); So I when I tried
I recently learned that when using onclick, for a button, the field name and
Recently I've learned that setting the charset using the meta tag is a pretty
Possible Duplicate: Using A* to solve Travelling Salesman Problem I have recently learned that
So I recently learned that I should absolutely be using parametrized query's to avoid
EDIT: I recently learned that this problem is actually two separate issues: 1) Using
I recently learned that table valued functions are not allowed with Entity Framework 4.1.
I recently learned that all stl containers have swap function: i.e. c1.swap(c2); will lead
I've recently learned how to join 2 arrays using the + operator in PHP.

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.