Where is this memory leaking when using static strings within functions while using threads?
Posted: Wed Oct 13, 2021 12:02 pm
Tested with the latest PureBasic 5.73. I was experimenting with threads when I spotted this.
The PureBasic application will continue to consume memory until it crashes:
This is interesting because the pointer to a static string within a procedure doesn't change. So where is the memory leaking from? Maybe the temporary string created during assignment isn't being freed?
The PureBasic application will continue to consume memory until it crashes:
Code: Select all
Procedure.s FuncStaticString()
Static string.s
string.s=LSet("",32,Chr(97+Random(25,0)))
EndProcedure
Procedure ThreadTest(null)
FuncStaticString()
EndProcedure
NewList threadPool()
threadCount.q=0
For i=1 To 10000
AddElement(threadPool())
thread=CreateThread(@ThreadTest(),#Null)
If Not thread
Debug "Last thread count: "+Str(threadCount)
DebuggerError("Thread entry is null")
EndIf
threadPool()=thread
threadCount+1
If i=10000
i=1
ForEach threadPool()
If Not threadPool()
DebuggerError("Thread entry is null")
EndIf
WaitThread(threadPool())
Next
ClearList(threadPool())
EndIf
Next i