News:

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

Main Menu

GetWindowLong, hEdit, GWL_WNDPROC

Started by jj2007, April 06, 2013, 06:02:51 AM

Previous topic - Next topic

dedndave

yah - you write a program that doesn't "balance" the GDI stuff and run it 100 times   :biggrin:

jj2007

Quote from: dedndave on April 09, 2013, 02:05:36 AM
yah - you write a program that doesn't "balance" the GDI stuff and run it 100 times   :biggrin:

Here is one that launches 1,000 times a Win GUI app that creates 1,000 brushes and exits without deleting them. That's a Million "unreleased" GDI handles ;-)

Read the disclaimer. On Win XP SP3 it seems to work fine :icon_mrgreen:

dedndave


jj2007

Quote from: dedndave on April 09, 2013, 04:30:46 AM
select them into a DC   :biggrin:
:greensml:

   CASE WM_PAINT
      invoke BeginPaint, hWnd, addr ps
      xchg eax, edi
      .While ctGDI<1000
         invoke CreateSolidBrush, ctGDI
         invoke SelectObject, edi, eax
         inc ctGDI
         SetWin$ hEdit=Str$("brush #%i", ctGDI)
      .endw
      invoke EndPaint, hWnd, addr ps
      invoke SendMessage, hWnd, WM_CLOSE, 0, 0
   ENDSW


dedndave


dedndave

before and after
oops, i lost 3 mb RAM   :redface:


jj2007

Quote from: dedndave on April 09, 2013, 05:14:36 AM
before and after
oops, i lost 3 mb RAM   :redface:

3 bytes for a brush? Hmmm...
Probably one of your svchost processes had a hiccup. Or Firefox loaded a page more.
Try again a hundred times ;-)

dedndave


jj2007

Quote from: dedndave on April 09, 2013, 06:20:11 AM
3 mb

Divided by one Million unreleased undeleted brushes = 3 bytes per brush :P

dedndave


jj2007

1000 brushes per launch * 1000 launches = 1Mio

dedndave

maybe brush objects is a bad example
i know i have seen problems related to GDI in some newbie programs - lol
i don't recall the exact circumstances, perhaps it was a DIB section or a DC
you run the program several times, then you have to reboot (or maybe log out/in)

jj2007

I guess you have to distinguish between
1. a memory leak because of repeated GDI object creations without DeleteObject inside the same app
2. creation of GDI objects once during WM_CREATE, no DeleteObject before ExitProcess.

Case 1 may play havoc with your system, of course. Case 2 depends on whether the object had any "global" implications (atoms, for example). If the object was in the memory that was allocated to the process, then it's gone for good when ExitProcess has done its work.

There is a lot of confusion on this issue - google for memory leak exitprocess to see some of it.

Here is a horribly confused thread: "Should I delete these memory before exit process", here a more solid page: "Does an Application memory leak cause an Operating System memory leak?"

See also M$ support DDEML: Memory Leak in Global Shared Memory - but even GlobalAlloc with the GMEM_DDESHARE flag does not use globally shared memory.