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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:52:58+00:00 2026-06-12T19:52:58+00:00

I have a memory leak that I’m trying to hunt down in my mfc

  • 0

I have a memory leak that I’m trying to hunt down in my mfc program. Typically I would do something like the following:

header file

// Leak Detection
#if defined(WIN32) && defined(_DEBUG)
     #define _CRTDBG_MAP_ALLOC
     #include <stdlib.h>
     #include <crtdbg.h>
#endif

cpp file

// Leak detection
#if defined(WIN32) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC)
    #ifdef DEBUG_NEW 
        #undef DEBUG_NEW
    #endif
    #define DEBUG_NEW new( _NORMAL_BLOCK, __FILE__, __LINE__ )
    #define new DEBUG_NEW
#endif

This technique works well in most files, but when I include it in some files such as my document, I get the error: error C2661: ‘CObject::operator new’ : no overloaded function takes 4 arguments

What’s the solution here? Should I be #undef-ing new somewhere or something?

Thanks!

  • 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-12T19:52:59+00:00Added an answer on June 12, 2026 at 7:52 pm

    I also use the same functionality as you for the purpose of leak detection.

    Either you can comment out or delete the DEBUG_NEW definition block, assuming you don’t need it any more for trapping memory leaks. Or if you still need it, leave it as it is and use

    #ifdef _DEBUG
    #undef new
        CMyOject* pMyObjectInst = new CMyObject();
    #define new DBG_NEW
    #endif  
    

    So, you undefine new just before object creation (see the line numbers in your Error List) and redefine it again immediately after, so that any memory leaks which occur after this object creation are still identifiable.

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

Sidebar

Related Questions

I am trying to track down a memory leak that I am having with
I have a memory leak problem that just can not understand! Watch this initialization
I have memory leak in the web application (servlet) that I am working on.
I have an .net app that seems to have a memory leak issue(s). The
I have a memory leak that I have isolated to incorrectly disposed direct byte
My Google Chrome taskbar clearly tells me that I have a memory leak. I've
I don't know why I have a memory leak here and would really appreciate
We have a memory leak that is causing our Node server to run out
I have a memory leak when i call a method that return me a
I have some PL/SQL code that I think might have a memory leak. Everytime

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.