Click here to Skip to main content
11,798,866 members (74,387 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: MFC GDI VC++

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
Edited 14-Apr-13 21:56pm
krmed at 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 at 16-Apr-13 5:55am
Good to know! My 5.
Jochen Arndt at 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
0 CPallini 505
1 OriginalGriff 503
2 Richard MacCutchan 321
3 Maciej Los 245
4 phil.o 244
0 OriginalGriff 2,270
1 Maciej Los 1,810
2 KrunalRohit 1,496
3 CPallini 1,425
4 Richard MacCutchan 1,109

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2015
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