From: Goran on
On Apr 28, 9:20 am, Girish <giris...(a)gmail.com> wrote:
> Hi,
> I  working in finding out the memory leak in the application which was
> developed in vc++2005. I am using  _CrtMemCheckpoint function to  find
> out the memory leak these function will be working only when the
> application is in debug mode and the project setting should in /MDD
> or /MTD .
> When ever I change my setting from /MD to /MDD I get a compiler error
> Error      251         error C2370: 'THIS_FILE' : redefinition;
> different storage class
> i.e   error is at
> #ifdef _DEBUG
> #define new DEBUG_NEW
> #undef THIS_FILE
> #pragma once
> static char THIS_FILE[] = __FILE__;
> #endif

We3ll, compiler is telling you that somehow you defined THIS_FILE more
than once. Without seeing all of the code you have, nobody can tell
where exactly is the problem. Is it possible that you put these macros
in a header file?

> When I try to remove this and build I can build the application but it
> crashes .

You have to tell people here what "crashes" mean more specifically.
You can gather much, much more info on "crashes". Where exactly is the
crash, in your sources? What is the crash? OS exception (e.g. access
violation) etc. How does your stack look like when crash occurs? Etc.

Don't be helpless. Look harder.

Goran.
From: Steve Achelis on
On Apr 28, 1:20 am, Girish <giris...(a)gmail.com> wrote:
> Hi,
> I  working in finding out the memory leak in the application which was
> developed in vc++2005. I am using  _CrtMemCheckpoint function to  find
> out the memory leak these function will be working only when the
> application is in debug mode and the project setting should in /MDD
> or /MTD .
> When ever I change my setting from /MD to /MDD I get a compiler error
> Error      251         error C2370: 'THIS_FILE' : redefinition;
> different storage class
> i.e   error is at
> #ifdef _DEBUG
> #define new DEBUG_NEW
> #undef THIS_FILE
> #pragma once
> static char THIS_FILE[] = __FILE__;
> #endif
>
> When I try to remove this and build I can build the application but it
> crashes .
> Could you please help me out what is changes  I need to make to run
> the application successfully.
>
> Thanks in Advance,
> Regards,
> Girish

Girish, for what it's worth, all of my cpp files (created by earlier
versions of MFC), have this code near the top (and compiles fine with
debug or release builds):

#ifdef _DEBUG
#define new DEBUG_NEW

#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

Not the pragma you showed. And so to Joe, the undef THIS_FILE was put
there by MFC...

As to finding your memory leak, I sometimes resort to the caveman-like
approach of removing blocks of code. I save a copy of my source code
(the entire folder), delete a big chunk of code (that will still allow
my app to run), see if it still leaks, and repeat until I can narrow
down what is causing the leak. This approach isn't guaranteed to
isolate the problem, but it usually works for me.

From: Tom Serface on
This article may also be useful to OP:

http://www.codeproject.com/kb/cpp/MemLeakDetect.aspx

I've, like you, often resort to the brute force method, just using Task
Manager and looking for blocks in the debug build that show up at the end of
the run in the Output window and things like that...

Tom

"Steve Achelis" <info(a)RescueRigger.com> wrote in message
news:7cb36cd1-fdec-4b19-8957-51d2afcf985a(a)u30g2000prd.googlegroups.com...
> On Apr 28, 1:20 am, Girish <giris...(a)gmail.com> wrote:
>> Hi,
>> I working in finding out the memory leak in the application which was
>> developed in vc++2005. I am using _CrtMemCheckpoint function to find
>> out the memory leak these function will be working only when the
>> application is in debug mode and the project setting should in /MDD
>> or /MTD .
>> When ever I change my setting from /MD to /MDD I get a compiler error
>> Error 251 error C2370: 'THIS_FILE' : redefinition;
>> different storage class
>> i.e error is at
>> #ifdef _DEBUG
>> #define new DEBUG_NEW
>> #undef THIS_FILE
>> #pragma once
>> static char THIS_FILE[] = __FILE__;
>> #endif
>>
>> When I try to remove this and build I can build the application but it
>> crashes .
>> Could you please help me out what is changes I need to make to run
>> the application successfully.
>>
>> Thanks in Advance,
>> Regards,
>> Girish
>
> Girish, for what it's worth, all of my cpp files (created by earlier
> versions of MFC), have this code near the top (and compiles fine with
> debug or release builds):
>
> #ifdef _DEBUG
> #define new DEBUG_NEW
>
> #undef THIS_FILE
> static char THIS_FILE[] = __FILE__;
> #endif
>
> Not the pragma you showed. And so to Joe, the undef THIS_FILE was put
> there by MFC...
>
> As to finding your memory leak, I sometimes resort to the caveman-like
> approach of removing blocks of code. I save a copy of my source code
> (the entire folder), delete a big chunk of code (that will still allow
> my app to run), see if it still leaks, and repeat until I can narrow
> down what is causing the leak. This approach isn't guaranteed to
> isolate the problem, but it usually works for me.
>
From: Girish on
Hi All,
First I need to say thanks for every one for proving your ideas.
I got the solution for the problem which i was facing.

by setting the below variables to 0

#define _HAS_ITERATOR_DEBUGGING 0
#define _SECURE_SCL 0

after define this we can remove the below code and build the
application with out any error or any crash.

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
#pragma once
static char THIS_FILE[] = __FILE__;
#endif


Regards,
Girish




On Apr 29, 3:32 am, Joseph M. Newcomer <newco...(a)flounder.com> wrote:
> I have no idea why MFC would put an #undef in, unless some earlier version had defined
> THIS_FILE as a macro.  But given the poor quality of information we were given about the
> problem (it didn't even say which file issued the error message!  Or which file had the
> code!) it is hard to play psychic detective and guess what is going on.
>                                 joe
>
>
>
>
>
> On Wed, 28 Apr 2010 06:34:08 -0700 (PDT), Steve Achelis <i...(a)RescueRigger.com> wrote:
> >On Apr 28, 1:20 am, Girish <giris...(a)gmail.com> wrote:
> >> Hi,
> >> I  working in finding out the memory leak in the application which was
> >> developed in vc++2005. I am using  _CrtMemCheckpoint function to  find
> >> out the memory leak these function will be working only when the
> >> application is in debug mode and the project setting should in /MDD
> >> or /MTD .
> >> When ever I change my setting from /MD to /MDD I get a compiler error
> >> Error      251         error C2370: 'THIS_FILE' : redefinition;
> >> different storage class
> >> i.e   error is at
> >> #ifdef _DEBUG
> >> #define new DEBUG_NEW
> >> #undef THIS_FILE
> >> #pragma once
> >> static char THIS_FILE[] = __FILE__;
> >> #endif
>
> >> When I try to remove this and build I can build the application but it
> >> crashes .
> >> Could you please help me out what is changes  I need to make to run
> >> the application successfully.
>
> >> Thanks in Advance,
> >> Regards,
> >> Girish
>
> >Girish, for what it's worth, all of my cpp files (created by earlier
> >versions of MFC), have this code near the top (and compiles fine with
> >debug or release builds):
>
> >#ifdef _DEBUG
> >#define new DEBUG_NEW
>
> >#undef THIS_FILE
> >static char THIS_FILE[] = __FILE__;
> >#endif
>
> >Not the pragma you showed. And so to Joe, the undef THIS_FILE was put
> >there by MFC...
>
> >As to finding your memory leak, I sometimes resort to the caveman-like
> >approach of removing blocks of code. I save a copy of my source code
> >(the entire folder), delete a big chunk of code (that will still allow
> >my app to run), see if it still leaks, and repeat until I can narrow
> >down what is causing the leak. This approach isn't guaranteed to
> >isolate the problem, but it usually works for me.
>
> Joseph M. Newcomer [MVP]
> email: newco...(a)flounder.com
> Web:http://www.flounder.com
> MVP Tips:http://www.flounder.com/mvp_tips.htm

From: Girish on
While changing the project setting from /md to /mdd or /mt to /mtd we
should make sure that all the dependency dll and modules are in the
same form i.e in debug mode if not then we would be facing this type
of problem .
in this case we could not use some of debugging functions like
_CrtMemCheckpoint to use this type function we need to define
#define _HAS_ITERATOR_DEBUGGING 0
#define _SECURE_SCL 0

which could give some ASSERT msg which would not crash be an issue.

Regards,
Girish

On Apr 28, 10:38 pm, Hector Santos <sant9...(a)nospam.gmail.com> wrote:
> Why do you have the
>
>       #pragma once?
>
> Just use this:
>
> #ifdef _DEBUG
> #define new DEBUG_NEW
> #endif
>
> I just checked something. If you have to use CrtMemCheckpoint, then
> you are not MFC ready.
>
> I have a lot of test and design code that are console only, where I
> will isolate a new class and do rapid development and testing under my
> programmer editor.
>
> To use the crtdbg.h, here is an example test code using this crtdbg
> facility:
>
> ---------------------- CUT HERE --------------------------
> // File: testurl.cpp
> //
> // cl testurl.cpp  /W3 /EHsc /MDd /D /Zi /Od /D "WINVER=0x500"
> //                 /D "WIN32" /D "_DEBUG" /D "_WINDOWS"
> //                 /FR /link /debug
> //
>
> #include <stdio.h>
> #include <windows.h>
>
> #ifdef _DEBUG
> #define _CRTDBG_MAP_ALLOC
> #include <crtdbg.h>
> #endif
>
> #include "url.cpp" // new URL parser
>
> void ParseUrl(const char *str)
> {
>     URL *url = urlparse(str);
>     printf("- %4s URL: %s\n", url?"GOOD":"BAD", str);
>     if (url) urlfree(url);
>
> }
>
> void main(char argc, char *argv[])
> {
> #ifdef _DEBUG
>     _CrtMemState memstate1;
>     _CrtMemState memstate2, memdiff;
>
>     // Send all reports to STDOUT
>     _CrtSetReportMode( _CRT_WARN,    _CRTDBG_MODE_FILE );
>     _CrtSetReportFile( _CRT_WARN,    _CRTDBG_FILE_STDOUT );
>     _CrtSetReportMode( _CRT_ERROR,   _CRTDBG_MODE_FILE );
>     _CrtSetReportFile( _CRT_ERROR,   _CRTDBG_FILE_STDOUT );
>     _CrtSetReportMode( _CRT_ASSERT,  _CRTDBG_MODE_FILE );
>     _CrtSetReportFile( _CRT_ASSERT,  _CRTDBG_FILE_STDOUT );
>
>     _CrtMemCheckpoint(&memstate1);
> #endif
>
>     ParseUrl("/public/test1.php?title=special:123");
>     ParseUrl("/public/test1.php?title=special/page_name");
>     ParseUrl("/public/test1.php?title=special:123/page_name");
>     ParseUrl("/public/test1.php?/title=special:123/page_name");
>
> #ifdef _DEBUG
>     _CrtMemCheckpoint(&memstate2);
>     if ( _CrtMemDifference( &memdiff, &memstate1, &memstate2 )) {
>        printf("***** MEM LEAK *******\n");
>        _CrtMemDumpStatistics( &memdiff);
>        _CrtMemDumpAllObjectsSince(&memdiff);
>        _CrtDumpMemoryLeaks();
>     }
> #endif}
>
> ---------------------- CUT HERE --------------------------
>
>
>
>
>
> Girish wrote:
> > Hi,
> > I  working in finding out the memory leak in the application which was
> > developed in vc++2005. I am using  _CrtMemCheckpoint function to  find
> > out the memory leak these function will be working only when the
> > application is in debug mode and the project setting should in /MDD
> > or /MTD .
> > When ever I change my setting from /MD to /MDD I get a compiler error
> > Error      251         error C2370: 'THIS_FILE' : redefinition;
> > different storage class
> > i.e   error is at
> > #ifdef _DEBUG
> > #define new DEBUG_NEW
> > #undef THIS_FILE
> > #pragma once
> > static char THIS_FILE[] = __FILE__;
> > #endif
>
> > When I try to remove this and build I can build the application but it
> > crashes .
> > Could you please help me out what is changes  I need to make to run
> > the application successfully.
>
> > Thanks in Advance,
> > Regards,
> > Girish
>
> --
> HLS