Restored from previous forum. Originally posted by LJ.
There is another leak on the same code, only an read statement is used with an array. The code is below. Keep clicking on the button and about every 3 clicks the .exe increases about 4K. This is the same code in the previous example that has no leak by Timo. The only difference is that I've added a READ command, it is as if the .s ARRAY in the UpdateScreen is not clearing itself.
Dim talk.s(18)
Dim prof.s(10)
OpenWindow(1, 128, 96, 320, 256, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget, "Background image example")
CreateGadgetList(WindowID())
CreateImage(1, WindowWidth(), WindowHeight())
StartDrawing(ImageOutput())
Box(0, 0, WindowWidth(), WindowHeight(), $ff)
FrontColor(0, 0, 0)
DrawingMode(1)
DrawingFont(LoadFont(0, "Times New Roman", 16))
Locate(64, 32)
DrawText("Background image")
StopDrawing()
ImageGadget(1, 0, 0, WindowWidth(), WindowHeight(), UseImage(1))
ButtonGadget = ButtonGadget(0, 80, 64, 160, 128, "My Button")
LoadFont(0, "Times New Roman", 16)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 0
Gosub UpdateWindow
EndSelect
EndIf
Until EventID=#PB_EventCloseWindow
End
UpdateWindow:
FreeGadget(0)
UseImage(1)
StartDrawing(ImageOutput())
Box(0, 0, WindowWidth(), WindowHeight(), $ff)
FrontColor(0, 0, 0)
DrawingMode(1)
DrawingFont(UseFont(0))
Locate(64, 32)
DrawText("Test image")
StopDrawing()
ButtonGadget = ButtonGadget(0, 80, 64, 160, 128, "My Button")
Restore screen1
For k = 1 To 17
Read tmp.s
talk(k)=tmp
Next k
talklines = 0
For k = 1 To 10
Read tmp.s
prof(k)=tmp
talklines = talklines + 1
If prof(k) = ""
talklines = talklines - 1
EndIf
Next k
SetGadgetState(1, UseImage(1))
ActivateGadget(0)
Return
DataSection
screen1:
Data.s "Sample data that the program is reading."
Data.s ""
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s ""
Data.s ""
Data.s ""
EndDataSection
Another Leak on Same Code, added....
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by LJ.
Thank you Fred. Here is the same code with using NewList and then attempting to clear with ClearList each time the UpdateWindow routine is called. This leaks about 4K every 3 clicks also.
Structure somestrings ; Define a structure for the list
talk.s
EndStructure
Structure somestringstwo ; Define a structure for the list
prof.s
EndStructure
NewList MyList.somestrings () ; Create the list with the structure pattern
NewList MyListtwo.somestringstwo () ; Create the list with the structure pattern
OpenWindow(1, 128, 96, 320, 256, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget, "Background image example")
CreateGadgetList(WindowID())
CreateImage(1, WindowWidth(), WindowHeight())
StartDrawing(ImageOutput())
Box(0, 0, WindowWidth(), WindowHeight(), $ff)
FrontColor(0, 0, 0)
DrawingMode(1)
DrawingFont(LoadFont(0, "Times New Roman", 16))
Locate(64, 32)
DrawText("Background image")
StopDrawing()
ImageGadget(1, 0, 0, WindowWidth(), WindowHeight(), UseImage(1))
ButtonGadget = ButtonGadget(0, 80, 64, 160, 128, "My Button")
LoadFont(0, "Times New Roman", 16)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 0
Gosub UpdateWindow
EndSelect
EndIf
Until EventID=#PB_EventCloseWindow
End
UpdateWindow:
ClearList(MyList())
ClearList(MyListtwo())
FreeGadget(0)
UseImage(1)
StartDrawing(ImageOutput())
Box(0, 0, WindowWidth(), WindowHeight(), $ff)
FrontColor(0, 0, 0)
DrawingMode(1)
DrawingFont(UseFont(0))
Locate(64, 32)
DrawText("Test image")
StopDrawing()
ButtonGadget = ButtonGadget(0, 80, 64, 160, 128, "My Button")
Restore screen1
For k = 1 To 17
Read a$
AddElement(MyList()) ; Lists never use indexes like arrays
MyList()\talk=a$ ; Fill the list using the structure pattern
Next k
talklines = 0
For k = 1 To 10
Read b$
talklines = talklines + 1
If b$ = ""
talklines = talklines - 1
EndIf
AddElement(MyListtwo()) ; Lists never use indexes like arrays
MyListtwo()\prof=b$ ; Fill the list using the structure pattern
Next k
SetGadgetState(1, UseImage(1))
ActivateGadget(0)
Return
DataSection
screen1:
Data.s "Sample data that the program is reading."
Data.s ""
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s ""
Data.s ""
Data.s ""
EndDataSection
Thank you Fred. Here is the same code with using NewList and then attempting to clear with ClearList each time the UpdateWindow routine is called. This leaks about 4K every 3 clicks also.
Structure somestrings ; Define a structure for the list
talk.s
EndStructure
Structure somestringstwo ; Define a structure for the list
prof.s
EndStructure
NewList MyList.somestrings () ; Create the list with the structure pattern
NewList MyListtwo.somestringstwo () ; Create the list with the structure pattern
OpenWindow(1, 128, 96, 320, 256, #PB_Window_SystemMenu|#PB_Window_MinimizeGadget, "Background image example")
CreateGadgetList(WindowID())
CreateImage(1, WindowWidth(), WindowHeight())
StartDrawing(ImageOutput())
Box(0, 0, WindowWidth(), WindowHeight(), $ff)
FrontColor(0, 0, 0)
DrawingMode(1)
DrawingFont(LoadFont(0, "Times New Roman", 16))
Locate(64, 32)
DrawText("Background image")
StopDrawing()
ImageGadget(1, 0, 0, WindowWidth(), WindowHeight(), UseImage(1))
ButtonGadget = ButtonGadget(0, 80, 64, 160, 128, "My Button")
LoadFont(0, "Times New Roman", 16)
Repeat
EventID = WaitWindowEvent()
If EventID = #PB_EventGadget
Select EventGadgetID()
Case 0
Gosub UpdateWindow
EndSelect
EndIf
Until EventID=#PB_EventCloseWindow
End
UpdateWindow:
ClearList(MyList())
ClearList(MyListtwo())
FreeGadget(0)
UseImage(1)
StartDrawing(ImageOutput())
Box(0, 0, WindowWidth(), WindowHeight(), $ff)
FrontColor(0, 0, 0)
DrawingMode(1)
DrawingFont(UseFont(0))
Locate(64, 32)
DrawText("Test image")
StopDrawing()
ButtonGadget = ButtonGadget(0, 80, 64, 160, 128, "My Button")
Restore screen1
For k = 1 To 17
Read a$
AddElement(MyList()) ; Lists never use indexes like arrays
MyList()\talk=a$ ; Fill the list using the structure pattern
Next k
talklines = 0
For k = 1 To 10
Read b$
talklines = talklines + 1
If b$ = ""
talklines = talklines - 1
EndIf
AddElement(MyListtwo()) ; Lists never use indexes like arrays
MyListtwo()\prof=b$ ; Fill the list using the structure pattern
Next k
SetGadgetState(1, UseImage(1))
ActivateGadget(0)
Return
DataSection
screen1:
Data.s "Sample data that the program is reading."
Data.s ""
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s ""
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s "Sample data that the program is reading."
Data.s ""
Data.s ""
Data.s ""
EndDataSection
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by freak.
Ok, tested much with your code, and things are clear now.
There was one leaking thing, that is fixed now, and there is another one, wich can't be fixed quickly, will be fixed for the next release (after v3.62)
The fixed one had something to do with Data reading.
The other one is, that ClearList() doesn't free Strings correctly.
Thanks for pointing things out...
Timo
Ok, tested much with your code, and things are clear now.
There was one leaking thing, that is fixed now, and there is another one, wich can't be fixed quickly, will be fixed for the next release (after v3.62)
The fixed one had something to do with Data reading.
The other one is, that ClearList() doesn't free Strings correctly.
Thanks for pointing things out...
Timo
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm