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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:17:53+00:00 2026-06-04T06:17:53+00:00

struct test_struct { test_struct() {} ~test_struct() {} }; #include <vector> #include <memory> #include <cstdio>

  • 0
struct test_struct
{
    test_struct() {}
    ~test_struct() {}
};

#include <vector>
#include <memory>
#include <cstdio>

int main()
{
    printf("ctor begin\n");
    {
        std::vector<std::unique_ptr<test_struct>> test_vec;
        const int count = 100000;

        for (auto i = 0; i < count; i++) {
            test_vec.emplace_back(new test_struct);
        }
        printf("dtor begin\n");
    }
    printf("dtor end\n");
}

I’m using VS2010, and found some ridiculous performance issue. The code above works well both in debug and release build (ctrl+f5), but when debugger is attached(f5), dtor call for unique_ptr class is intolerably slow. The result machine code is fairly optimized, so I don’t expect that it’s compiler issue rather than debugger’s, but I don’t know how to deal with it. My question is

  • Is this problem able to be reproduced on your machine?
  • What’s the reason of this behaviour?
  • Is there any workaround?
  • 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-04T06:17:54+00:00Added an answer on June 4, 2026 at 6:17 am

    The slowdown is caused by memory checking that occurs whenever memory is freed. However, this is a special system-/debugger-level heap, and isn’t anything you can control from within your program.

    There’s a great article on the issue. To summarize: you have to set an environment variable to disable it!

    Luckily, you can set project-specific environment variables from the Debugging options in the Project Settings for your project, so that the environment variable is only applied to your program.

    I used this simplified program to test:

    #include <iostream>
    #include <memory>
    #include <vector>
    
    int main()
    {
        std::cout << "ctor begin" << std::endl;
        {
            std::vector<std::unique_ptr<int>> test_vec;
    
            for (unsigned i = 0; i < 100000; i++)
                test_vec.emplace_back(new int);
    
            std::cout << "dtor begin" << std::endl;
        }
        std::cout << "dtor end" << std::endl;
    }
    

    By setting _NO_DEBUG_HEAP=1 as an environment variable (either system-wide, which I won’t recommend, or through the Debugging options), the code runs in roughly the same amount of time irrespective of whether or not the debugger is attached.

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

Sidebar

Related Questions

The following code: #include <vector> struct S { int x, y; }; int main()
my test code is below: main1.c: #include <stdio.h> extern struct tt ; int main()
For the following code: #include<iostream> #include<vector> #include<string> using namespace std; struct Test { string
#include <iostream> using namespace std; struct test { int i; double h; int j;
I am curious why this code works: typedef struct test_struct { int id; }
This is my code: #include <algorithm> #include <vector> #include <string> using namespace std; class
Using Visual Studio 2010 SP1: #include <vector> //namespace XXX { struct Test { bool
I've got a very simplistic application: #include <vector> void android_main(struct android_app* state) { }
#include <iostream> template<typename T, int = 0> struct test { typedef char type[3]; };
Given: template<class T> struct test { void foo(int b); void testFunc( int a )

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.