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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T07:13:58+00:00 2026-06-16T07:13:58+00:00

#define _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> struct A { A(char* p) : p(p) {}

  • 0
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>

struct A
{
    A(char* p)
        : p(p)
    {}

    ~A()
    {   
        delete this->p;
    }

    char* p;
};

int main()
{
    A a(new char);
    _CrtDumpMemoryLeaks();
}

After running in debugging mode, the output window of Visual Studio 2012 shows:

Detected memory leaks!
Dumping objects ->
{142} normal block at 0x007395A8, 1 bytes long.
 Data: < > CD 
Object dump complete.

What’s the cause?

  • 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-16T07:14:00+00:00Added an answer on June 16, 2026 at 7:14 am

    Perhaps it’s dumping the memory leaks before the destructor is actually called? Try:

    int main()
    {
         {
             A a(new char);
         }
         _CrtDumpMemoryLeaks();
    }
    

    I suggest using the standard’s (or boost’s) smart pointer classes, such as unique_ptr or shared_ptr, instead of dealing with new/delete directly with raw pointers.

    EDIT:
    Removed the suggestion to set the pointer to NULL, since delete deals with that.

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

Sidebar

Related Questions

#define STRMAX 50 struct Person { char sName[STRMAX]; int iAge; }; typedef struct Person
#define L 1 #define M L+1 int main(void){ int N=L*M*2; char s [N]={'1','2'}; printf(%d,
When I run the following code: #include gmock/gmock.h #include gtest/gtest.h #define _CRTDBG_MAP_ALLOC #include <crtdbg.h>
#define MAX 100 struct bs{ int ab; int ac; }be; struct s{ be b;
#define f(g,g2) g##g2 main() { int var12=100; printf(%d,f(var,12)); } The above program prints 100
#define LOG(format,...) Logger::Log(format,__VA_ARGS__) #define STRIP(netIp) GeneralUtils::inet_ntop_(netIp) string GeneralUtils::inet_ntop_(unsigned int netIp){ char strIP[INET_ADDRSTRLEN]; in_addr sin_addr;
#define BUFSIZE 256 int escape_single_quotes(char *to, char *from, int max) { int l= 0;
#define BUF_SIZE 10 char *html = foo:baa\r\nxxx:yyyy:\r\nLocation:........................................\r\Connection:close\r\n\r\n; char *p = (char*)html, *buf, *pbuf, *tbuf;
#define HISTORY_SIZE 50 #define INPUT_SIZE 512 /*Max input size*/ char input[INPUT_SIZE]; /*Holding user input
I define HttpClient in 2 different ways: 1. Plain vanilla: client = new DefaultHttpClient();

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.