GDI Leak Detection

Source: Internet
Author: User

The screen and editing functions were added to the previous paragraph in an IM communication tool similar to QQ. However, during the test, it was found that after dozens of consecutive times, the system would display a white screen, at first, I thought it was related to the frequent flash white in Windows 7. When the screen was captured to the flash, the white screen was generated. Later I found that the GDI memory was insufficient and the failure to apply for the GDI memory texture failed. So I found a tool leaked by GDIProgramThe following describes the usage of the two GDI leak detection tools and some precautions for GDI programming.

First: gdindicator supports win7 + XP

1. Start the program to be detected and gdindicator. There is no requirement on the startup sequence. After F5 refresh, we can see all processes in the system and the number of resources used.

Find the process you want to view. Here, our program is tpcommoncontroltest. Double-click it to enter the list of non-released GDI objects.

 

Click the GDI object in the list control on the left to view it. For available bitmap objects, you can also view thumbnails.

2. perform operations that may cause leakage and restore. For this program, it is to open the chat window, screen, and close the chat window.

If there is no GDI leakage, the GDI object should not be changed after the above operations are performed. If so, find the leaked GDI object based on the difference value.

3. It is the usage of the GDI object after the operation. Based on the difference value, it focuses on the leakage analysis.

According to the comparison, we found that a new bitmap2 DC object is added, and then double-click the tpcommoncontroltest process, combinedCodeAnalyze to see where the DC is used and whether it is released. This tool is not very accurate and does not provide call stacks. It can only be analyzed and searched by programmers based on new objects.


The second tool, gdileakdetector, supports XP, and win7 does not support very well. It can precisely locate the location of GDI leakage:

Usage:

1. Open gdileakdetector, find the program to be detected, and click "run program ".

2. perform operations that may cause leakage, exit the program, and click the GDI leak list on the left to see which one can be modified.

As shown in, it is easy to find that DC leaks exist in copyclipbrd. Check the function and find that DC is created through the createcompatibledc function, but releasedc is used for release. This is incorrect, deletedc should be used to release the DC applied for by createcompatibledc, And the DC resource obtained by getdc will be released by releasedc. Otherwise, the GDI will be leaked.

 

Note:

Http://blog.csdn.net/bobob/archive/2005/12/29/565188.aspx

1. Release the created GDI object with deleteobject, create the DC with deletedc, and release the DC with getdc with releasedc.

2. Create, delete, create1, create2, delete2, and delete1.

3. Drawing steps

A creates a memory-compatible DC (createcompatibledc)
B. Create a memory-compatible Bitmap (createcompatiblebitmap)
C. The associated memory is compatible with DC and bitmap (SelectObject)
D. Drawing
E. bitblt to Target DC
F. Disconnect memory compatibility between DC and bitmap (SelectObject)
G. Destroy memory compatible with bitmap
H. Destroy memory compatible DC

From: http://hi.baidu.com/plqnmxukpmbftud/item/ccd9b5caec8fc303b67a249b

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.