Click here to Skip to main content
12,998,892 members (31,112 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I am creating and deleting MFC gdi objects and watching the number of GDI Objects that application uses via Windows Task Manager.

When i create a CBrush object by CreateSolidBrush i observe an increment in GDI Object count of application. However when i delete the brush by DeleteObject there happens no change.

Does anybody have an idea why GDI object count does not decrements when i delete the brush i have created?

Thanks in advance.
Sanoop Das K
Posted 14-Apr-13 21:52pm
Updated 14-Apr-13 21:56pm
krmed 15-Apr-13 9:18am
What do you do with the brush between the time you create it and then destroy it?

If you select the object into a DC, you must remember to "unselect" it (select a different object) before you destroy it, as you cannot destroy an object that is currently selected in a DC.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

As far as I know, the memory of solid brushes is not always freed when calling DeleteObject() but reserved and reused with following CreateSolidBrush() calls by simply replacing the color value.

This can be verified by calling GetGuiResources() before and after creation and deletion. In some cases, the count will increase upon creation and not decrease upon deletion as noted by you. In other cases, the count will not increase upon creation indicating that a previous brush is reused.
nv3 16-Apr-13 5:55am
Good to know! My 5.
Jochen Arndt 16-Apr-13 6:06am
Thank you.
But this is not documented. I just verified it as described.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100