Click to See Complete Forum and Search --> : memory leak issues


sameerhanda
July 23rd, 2004, 10:30 AM
:eek:Ok I have just inherited a piece of C++ .NET code( i feel like a proud PAPA ).
This C++ .NET code in the form of assemblies that interface with another set of C# assemblies which are being called from a ASP.NET project. The problem is that when the ASP .NET project is executed..i can just see the resources on this process going from 72,000K to almost 154,000K in a hurry and progressively getting "worst".
So, my first thought is memory leak in the C++ assemblies. Here are the questions.

1. Can i use #define CRTDBG_MAP_ALLOC to debug memory leaks in dll's.
2. Technically according to MS I should put
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
at the start of my program.

So, since it is a just a class library..where would the _CrtSetDbgFlag go.

thanks

Sameer

Mick
July 23rd, 2004, 10:37 AM
:eek:Ok I have just inherited a piece of C++ .NET code( i feel like a proud PAPA ).
This C++ .NET code in the form of assemblies that interface with another set of C# assemblies which are being called from a ASP.NET project. The problem is that when the ASP .NET project is executed..i can just see the resources on this process going from 72,000K to almost 154,000K in a hurry and progressively getting "worst".
So, my first thought is memory leak in the C++ assemblies. Here are the questions.

1. Can i use #define CRTDBG_MAP_ALLOC to debug memory leaks in dll's.
2. Technically according to MS I should put
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
at the start of my program.

So, since it is a just a class library..where would the _CrtSetDbgFlag go.

thanks

Sameer

CRTDBG_MAP_ALLOC is the older define to track malloc() calls to the acutal line/file of the call though it is still useful when you do indeed use malloc directly. New is usually redefined to new(_NORMAL_BLOCK,__FILE__, __LINE__)

As for the _CrtSetDbgFlag(...) put it as early as you can, either in main(...), DllMain(...) ie: the top level called entrypoint, in the first global C++ object that gets constructed, or in the ctor of the class library.