![]() |
Multimedia »
GDI+ »
General
Intermediate
GDI+ and MFC memory leak detectionBy Zoltan CsizmadiaGDI+ and MFC memory leak detection |
VC6Win2K, WinXP, Win2003, Visual Studio, MFC, GDI+, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
When I started to use GDI+ with MFC in VC++ 6.0 I ran into some annoying problems:
DEBUG_NEW
macros
Here is the solution!
Include GdiplusH.h in stdafx.h:
// GDI+ helper file
#include "GdiplusH.h"
_CrtXXX
functions to detect memory leaks, set an allocation breakpoint, save
and compare memory states, etc.DEBUG_NEW
GDI+ is using GdipAlloc
and GdipFree for allocating memory for GDI+ objects.
Probably they have their own memory allocation lists in gdiplus.dll, but
unfortunately there is no exported API to get any memory leak information. But
GDI+ objects can be located on stack (for example: creating a local variable in
a function), so there is no special initialization for these memory regions, so
we do not have to use GdipAlloc or GdipFree. If we
call the CRT debug version of memory allocation and deletion functions instead
of GdipAlloc/Free, we can detect memory leaks very
easily using the well known _CrtXXX functions.
GDIPLUS_NO_AUTO_INIT
- GDI+ won't be initialized at program startup. You have to
create a GdiPlus::GdiPlusInitialize variable
to initialize GDI+ (GDI+ will be uninitialized, when destructor is called
for this variable).GDIPLUS_USE_GDIPLUS_MEM
- GdipAlloc and GdipFree is used for
memory operations. In this case _Crt functions cannot be used to
detect memory leaksGDIPLUS_NO_AUTO_NAMESPACE -
Gdiplus namespace won't be defined as a used namespace. In this case you
have to use Gdiplus:: prefix.| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 10 Sep 2003 Editor: Nishant Sivakumar |
Copyright 2003 by Zoltan Csizmadia Everything else Copyright © CodeProject, 1999-2009 Web09 | Advertise on the Code Project |