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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:47:33+00:00 2026-05-28T02:47:33+00:00

In Microsoft Visual C++ (VS 2008/2010) using a number of Standard Template Library containers

  • 0

In Microsoft Visual C++ (VS 2008/2010) using a number of Standard Template Library containers like std::set or std:vector you will run into memory leaks with this:

#include <set>
#include <stdlib.h>
#include <crtdbg.h>
#define _CRTDBG_MAP_ALLOC

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    printf("I'm leaking\n");

    std::set<int> s;

    _CrtDumpMemoryLeaks();
    return 0;
}

After you run the program, you’ll get some output like this:

Detected memory leaks!
Dumping objects ->
{209} normal block at 0x005E9C68, 20 bytes long.
 Data: <h ^ h ^ h ^     > 68 9C 5E 00 68 9C 5E 00 68 9C 5E 00 CD CD CD CD 
{208} normal block at 0x005E9C20, 8 bytes long.
 Data: <  ;     > F8 FE 3B 00 00 00 00 00 
Object dump complete.

Here is the solution to this: Just enclose the definition in braces like this:

int _tmain(int argc, _TCHAR* argv[])
{
    printf("I'm not leaking any more\n");

    {
        std::set<int> s;
    }
    _CrtDumpMemoryLeaks();
    return 0;
}

It’s a strange behavior and I’m wondering if this is a Bug in Microsoft Compilers or some STL-Problem? I guess it’s the former. If maybe anyone tried this on a Linux-System, it would be interesting to know…

  • 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-28T02:47:33+00:00Added an answer on May 28, 2026 at 2:47 am

    How is the first example a leak? s is still in scope, so of course it still has memory associated with it. You’d have to make your memory leak detection call after _tmain returns to get a valid answer.

    In your second example, s is out of scope and has been destroyed, so it’s no surprise that it has no more memory associated with it.

    You just need to call the leak checker at spots in your code that make sense.

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

Sidebar

Related Questions

New microsoft's IDEs like Visual Studio 2008 or 2010 creates exe files with manifest
I'm using Microsoft Visual C# 2008 Express. In my main form, there's that X
I am using Microsoft Visual Web Developer 2008 Express. I've made an ASP.NET MVC
C#3 (Visual Studio 2008) introduced a breaking change to the language ( http://msdn.microsoft.com/en-us/library/cc713578.aspx ,
I'm using Microsoft Visual Studio 2008 (VC9) to compile a project that has a
When using Visual Studio 2008 or 2010, every time you attach to IIS w3wp.exe
Sometimes, when I'm ckeckin out source code using Microsoft Visual Studio Team System 2008
Background-info: I'm using Microsoft Visual Web Developer 2010 Express. Info about my (lack of)
I want to create the webpart in Visual studio 2010/2008 environment with microsoft given
I am using Visual Studio 2010 but has received an external library developed for

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.