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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:56:31+00:00 2026-05-21T13:56:31+00:00

I got a problem when I tried to create and delete an instance of

  • 0

I got a problem when I tried to create and delete an instance of the class in a loop.
Execution time of iterations is quite different. As I understand it, this is associated with the removal of objects from memory. However, the behavior of this operation I do not understand. Why time is different? How do I fix it? Time is steady when I’m deleting the object in a separate thread.

class NODE{

    public:
        NODE(){}

        NODE* add(NODE* node)
        {
            children.push_back(node);
            return node;
        }

        virtual ~NODE()
        {
            for(vector<NODE*>::iterator it = children.begin(); it != children.end(); ++it)
            {
                delete *it;
            }
        }

        vector<NODE*> children;

};

NODE* create()
{
    NODE* node( new NODE() );

    for (int i=0; i<200;i++) {
        NODE* subnode = node->add( new NODE());
        for (int k=0; k<20; k++) subnode->add( new NODE());
    }

    return node;
}

int main()
{
    NODE* root;
    unsigned t;

    for (int i=0; i<30; i++){
        t = clock();
        cout << "Create... ";
        root = create();
        delete root;
        cout<< clock()-t << endl;
    }
}

ADDED:
I’m confused. When I run program out of VS it works fine…

  • 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-21T13:56:32+00:00Added an answer on May 21, 2026 at 1:56 pm

    In addition to what other answers say you have to account for Visual C++ 10 runtime heap being thread-safe. This implies that even when you only have one thread you encounter some overhead facilitating heap operations being thread-safe. So one reason you see such poor results is that you use a universal but rather slow heap implementation.

    The reason why you get different timing with/without the debugger is a special heap is used when a program is started under debugger (even in Release configuration) and that special heap is also relatively slow.

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

Sidebar

Related Questions

I've got a problem with NoClassDefFound exception in Grails 2.0 when I tried to
i got a weird problem regarding egrep and pipe I tried to filter a
have a nice day. I got problem when trying to create an image from
I've got problem with sorting my lucene.net index in .NET. I tried almost every
I tried git integrated with xcode 4, but got problem on merge a branch
Im trying to create a calendar application. I've got a problem with the way
i've got a problem I need help with. I am trying to create a
i got problem with my code and hopefully someone able to figure it out.
I got problem with sending data in Android using httpPost. I found some example,
I've got problem with DirectX in C#. I want to draw some lines. Firstly

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.