On 10/9/06, [EMAIL PROTECTED] <
[EMAIL PROTECTED]> wrote:
[chop]
Hi All,
I'm having problems with memory leaks, and was hoping that someone might be able to assist.
Can anyone suggest what might be going wrong please
I don't know for your specific problem, but:
Memory leaks are a pain, but thanks to Visual C++'s debugging features you can track them down quite easily.
Start by indicating to the CRT you want to use the integrated allocation tracing mechanism by adding
#ifdef _DEBUG
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
/* Optionally, you can redefine the operator new so that the CRT debugging tool
points to the correct file and line number rather than crtdbg.h (689); we must use
'OSG_NEW' instead of 'new' all over the place for it to work, though.*/
#define OSG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#endif //_DEBUG
in an always included file. I suggest you add this to the <osg/Export> file, just above the __declspec(dllimport) stuff. Be warned though that if your app requires any windows headers, you should include them *before* this block. It will certainly be the case for you since you use ActiveX (and probably ATL or MFC). For instance, I have in one of my projects the following includes & defines:
#define _WIN32_DCOM
#define _WIN32_WINNT 0x0400
#include <winsock2.h>
#include <comdef.h>
#include <wbemidl.h>
#include <atlbase.h>
It was quite a headache to get them ordered properly.
At the beginning of the main() function (or even better, in the constructor of a static, global initializer class, which will be called before main()), write
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
This will make your program dump a list of memory leaks upon exit when ran with the debugger. Each of them has an ID number (and the file and line number if you used the #define OSG_NEW trick).
Choose one you want to get rid of, and add just after the _CrtSetDbgFlag() call
_CrtSetBreakAlloc(<block-ID>)
Now your program when ran in debug mode will automatically break upon the allocation of the block that is not freed later on (and crash if ran without debugging :)
Hope this helps
Thibault
_______________________________________________ osg-users mailing list [email protected] http://openscenegraph.net/mailman/listinfo/osg-users http://www.openscenegraph.org/
