Common Memory leakage and GDI leakage in the Development

Source: Internet
Author: User
Tags win32 window

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.