The MASM Forum

General => The Campus => Topic started by: r0ger on November 14, 2021, 01:01:35 AM

Title: gdi leak overflow on meatballs effect
Post by: r0ger on November 14, 2021, 01:01:35 AM
hi all ,

3 months ago i've ripped some aboutbox effect from a release, then i've noticed the GDI objects start to increase resulting in GDI leaking .
does it have to be the timer problem or is it just the font initialization causing this problem ?
Title: Re: gdi leak overflow on meatballs effect
Post by: hutch-- on November 14, 2021, 01:15:38 AM
Hi roger, I don't have the time to do a full analysis but a quick look found SelectObject() but not reselecting the old object when finished and this will give you a GDI leak.
Title: Re: gdi leak overflow on meatballs effect
Post by: fearless on November 14, 2021, 01:35:01 AM
Every time AboutInit is called a new DC with a bitmap and font are created. Plus you are also creating solid brushes every time the about dialog is launched. None of these is cleaned up on exit.

Ideally you might create the brushes at start of the program and clean up on exit of program and save them to handles so they can be reused throughout the program. Or create at AboutInit of the about dialog, save handles and then clean up at end of dialog. Same goes with the DC and font created at AboutInit.
Title: Re: gdi leak overflow on meatballs effect
Post by: r0ger on November 14, 2021, 03:22:21 AM
fearless, thanx so much for your suggestion.

removed the solid brushes before the cmp [uMsgz],110h (initdialog) and now it doesn't cause GDI leaks.

invoke  CreateSolidBrush,0
mov     [hColor], eax


as of these codes below which i've removed from the beginning of AboutProc subroutine , if i had initiated the black brush only on WM_CTLCOLORDLG and then initialize with hColor variable , it still causes GDI leaks but only when you move the aboutbox.
so i now suggest this if you don't want to cause any GDI leaks nor when you move the dialog nor while the animation plays :

mov eax,[wParamz]
invoke SetBkColor,eax,Black
invoke GetStockObject,BLACK_BRUSH
ret


problem solved ! :thup: