Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC GDI VC++
Hi,
 
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 22:52pm
Edited 14-Apr-13 22:56pm
v2
Comments
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
good
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.
  Permalink  
Comments
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 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 Andreas Gieriet 90
4 Jochen Arndt 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 16 Apr 2013
Copyright © CodeProject, 1999-2014
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