Click here to Skip to main content
16,015,296 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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
Updated 14-Apr-13 21:56pm
v2
Comments
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

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.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900