Announcement

Collapse
No announcement yet.

PRINTDLG and GDI object count?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • PRINTDLG and GDI object count?

    Hi folks,

    While researching a memory leak in an application, I found that the PrintDLG() creates over 20 GDI objects, and while these are not recreated with subsequent calls to PrintDLG(), these handles are not released until the app terminates.

    So, I started to consider what would happen when this API was used in a separate thread... how much of a 'leak' would occur?

    As a result, I wrote the following test code and ran it. It creates 5 PRINTDLG Dialog boxes, and displays a MSGBOX. While the MSGBOX was open I used Task Manager to look at the GDI count.

    The results are not 100% consistent, but at it's worst, the app had 119 GDI objects allocated! As I closed each Dialog, the GDI count dropped only by one object.

    Anyone got any ideas how to "flush" these objects?

    Code:
    #COMPILE EXE
    #INCLUDE "comdlg32.inc"
     
    FUNCTION T1(BYVAL z AS LONG) AS LONG
        DIM PD AS PRINTDLGAPI
        PD.lStructSize   = SIZEOF(PD)
        IF PrintDlg(PD) THEN
            IF PD.hDevMode  THEN GlobalFree PD.hDevMode
            IF PD.hDevNames THEN GlobalFree PD.hDevNames
        END IF
    END FUNCTION
     
    FUNCTION PBMAIN
        FOR x& = 1 TO 5
            THREAD CREATE T1(x&) TO Result&
            THREAD CLOSE Result& TO Result&
        NEXT x&
        MSGBOX "How many ?" ' while this is displayed, test for GDI objects in TaskMan.
    END FUNCTION

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

  • #2
    Funny ... Win2000, SP1. I removed all printers. Appears simple dialog - "add printers before".
    On my PC PrintDlg eats 25 (- 1) objects in any case - there are printers or not.
    Looks like clean program mistake - very doubt that these GDI objects are used in dialogs.

    Time to push Bill or to write own PrintDlg .

    One thought - if OS sees GDI objects (and they should be "free"), may be it's possible to enumerate GDI objects (interesting, how) and to delete them ?





    ------------------
    E-MAIL: [email protected]

    Comment

    Working...
    X