News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

GDi Leak Detector

Started by guga, September 08, 2014, 09:59:35 PM

Previous topic - Next topic

guga

A set of small functions to detect GDI leaks


; pGuiCount: Pointer to a variable that will hold the total amount of objects used on the current process

Proc StartGdiCapture:
    Arguments @pGuiCount
    Uses ecx, edx, edi, eax

    call 'KERNEL32.GetCurrentProcess'
    call 'user32.GetGuiResources' eax, &GR_GDIOBJECTS
    mov edi D@pGuiCount
    mov D$edi eax

EndP



;;
    GuiCount: The total amount of objects previously retrieved by StartGdiCapture

    Returned Value
         If the function returns 0, it means there is no leaks
               if eax is bigger then Zero, it means you have a gdi leak
               A negative value  means the gdi objects are being released (When you call DestroyWindow, for example)
;;


Proc IsGdiLeaking:
    Arguments @GuiCount
    Uses ecx, edx, edi

    call 'KERNEL32.GetCurrentProcess'
    call 'user32.GetGuiResources' eax, &GR_GDIOBJECTS
    sub eax D@GuiCount

EndP



Example of usage

[GdiCount: D$ 0]
call StartGdiCapture GdiCount

call MyRoutine

call IsGdiLeaking D$GdiCount

If eax >s 0 ; If eax is positive and bigger then 0
     ; Found leak. do something
End_If



References and issues for this functions:
http://stackoverflow.com/questions/18454380/how-to-correct-the-gdi-resource-leakage
http://blogs.msdn.com/b/oldnewthing/archive/2010/09/23/10066473.aspx
http://msdn.microsoft.com/en-us/magazine/cc301756.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/dd144844%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms683192%28v=vs.85%29.aspx
https://www.relisoft.com/win32/gdileaks.html
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Gunther

Hi Gustavo,

thank you for the code and the interesting links. Very good background information.  :t

Gunther
You have to know the facts before you can distort them.

guga

Hi Guther

You´re welcome  :t

I saw that info an hour ago and made those small functions to give a test. It seems to work as expected.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Siekmanski

Creative coders use backward thinking techniques as a strategy.

Gunther

Hi Gustavo,

Quote from: guga on September 08, 2014, 10:52:43 PM
I saw that info an hour ago and made those small functions to give a test. It seems to work as expected.

yes it does. Moreover, these are important informations for graphics programming.

Gunther
You have to know the facts before you can distort them.

guga

Tks Siekmanski and Gunther

I hope it helps others. I was reading in one of those articles about using gdiflush whenever you change from memory DC to the loaded file in memory. I didn´t tested the gdiflush to see if it really releases the cache as it is reported here
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

jj2007

Hi Gustavo,

Haven't seen GDI leaks for a while but there were times when I would have desperately needed this tool :icon14:

P.S.: "10% of alcoholic levels in your blood." - are you sure? That is far off the Ballmer peak ::)

guga

Hi JJ

Tks :biggrin:

QuoteP.S.: "10% of alcoholic levels in your blood." - are you sure? That is far off the Ballmer peak

Ok, ok 10% is too much  :icon_mrgreen: :icon_mrgreen: But i´m used to drink one beer or two while coding  :icon_mrgreen:
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

Gunther

Jochen,

Quote from: jj2007 on September 09, 2014, 03:26:20 AM
P.S.: "10% of alcoholic levels in your blood." - are you sure? That is far off the Ballmer peak ::)

that was a good one.  :lol: Do you have some background information about that?

Gunther
You have to know the facts before you can distort them.