mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2026-01-27 11:54:56 +01:00
fcl-base: fpthreadpool: Dispose TThreadPoolList threads to prevent leaking memory
This commit is contained in:
parent
211db1d672
commit
e9dc21e4bc
@ -472,7 +472,29 @@ begin
|
||||
end;
|
||||
|
||||
destructor TFPCustomSimpleThreadPool.TThreadPoolList.Destroy;
|
||||
var
|
||||
Threads: array of TThread = ();
|
||||
Thread: TThread;
|
||||
TempList: TList;
|
||||
I: Integer;
|
||||
begin
|
||||
TempList := FList.LockList;
|
||||
|
||||
{ Copy threads to a separate array to avoid holding the lock while terminating threads }
|
||||
SetLength(Threads, TempList.Count);
|
||||
for I := 0 to TempList.Count - 1 do
|
||||
Threads[I] := TThread(TempList[I]);
|
||||
|
||||
FList.UnlockList;
|
||||
|
||||
{ Now terminate and free threads outside the lock }
|
||||
for Thread in Threads do
|
||||
begin
|
||||
Thread.Terminate;
|
||||
Thread.WaitFor;
|
||||
Thread.Free;
|
||||
end;
|
||||
|
||||
FreeAndNil(FList);
|
||||
Inherited;
|
||||
end;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user