Common Memory leakage and GDI leakage in the Development
I. GDI leak detection method:
In the software test stage, you can use the procexp.exe tool or select a GDI object in the task manager to view the usage of the software's GDI object.
Note: The created GDI objects must be released using deleteobject. The created DC must be released using deletedc. The DC obtained by getdc should be released using releasedc.
The following are some common functions:
1. Check getwindowdc () for releasedc ();
2. Check getdc (); Whether releasedc () exists ();
3. cbrush Detection:
Createsolidbrush ()-"deleteobject ();
4. Check the paint brush cpen
Createpen ()-> deleteobject ();
5. Check the cfont font
Createfont-> deleteobject ();
Createpointfont ()-> deleteobject ();
6. Check to create the Win32 window
Hwnd =: createwindow ()-> destroywindow (hwnd );
7. cbitmapbmp;
BMP. createcompatiblebitmap (& DC, rcclient. Width (), rcclient. Height ());
BMP. deleteobject ();
8. cfont * poldfont = PDC-> SelectObject (& m_font );
Whether there is PDC-> SelectObject (poldfont );
9. crgn
Createroundrectrgn ()-> deleteobject ();
10. Graphics GC (PDC)-> GC. releasedc (PDC );
11. In the cdialog dialog box create (), destroywindow () is required ();
12. closehandle (handle) is used to release the handle obtained through the function;
Example: handle, hbrush, Hpen
Handle hfile = createfile ();-> closehandle (hfile );
Ii. Memory detection methods:
Check whether memory leakage occurs by checking the memory leakage in the task manager or procexp.exe.
1. Check whether the following functions correspond one to one:
New-> Delete;
Malloc-> free;
Globalalloc-> globalfree
2. detect leakage through the debugger and CRT debugging heap
Put this statement in the software end part _ crtdumpmemoryleaks (); run it under debuggingProgramIf there is any leakage, the memory leakage information will be displayed in the output window.
3. Use a memory leak detection tool such as bchecker6.01, which is suitable for vc6 and can be used later.
From: http://blog.csdn.net/lin_angle/article/details/6603572