My old routines were loading icons for displaying in a ListIconGadget that got cleared and rebuilt as needed, which is quite regularly (several times an hour) depending on what the user needed.
The start of my app has a bunch of icons embedded like this:
Code: Select all
Global Catch_Img_Document=ImageID(CatchImage(#PB_Any,?Img_Document))
Global Catch_Img_Folder=ImageID(CatchImage(#PB_Any,?Img_Folder))
When refreshing the ListIconGadget, I was doing it like this:
Code: Select all
For i=1 To itemcount
Select icon$
Case "document" : icon=Catch_Img_Document
Case "folder" : icon=Catch_Img_Folder
EndSelect
AddGadgetItem(#LIG,0,text$,icon)
Next
That was causing the GDI leak. It seems just copying the
handle of an icon to a
variable ("icon") was creating a new icon behind the scenes?
So all I did to fix it was copy the icon to the variable, add the copy to the ListIconGadget, and then destroy the copy:
Code: Select all
For i=1 To itemcount
Select icon$
Case "document" : icon=CopyIcon_(Catch_Img_Document)
Case "folder" : icon=CopyIcon_(Catch_Img_Folder)
EndSelect
AddGadgetItem(#LIG,0,text$,icon)
DestroyIcon_(icon) ; Prevents GDI leak.
Next
@Fred: Should adding icons to a ListIconGadget like my first example even cause a GDI leak? Maybe it's a PureBasic bug?