This is a simplified version of what I had in my app.
procedure Test();
var
TerminateProc: TThreadProcedure;
S: string;
begin
S := 'Terminated';
TerminateProc :=
procedure
begin
ShowMessage(S);
end;
TThread.CreateAnonymousThread(
procedure
begin
// Do stuff
TThread.Queue(nil, TerminateProc);
TerminateProc := nil; // Memory leak without this
end).Start;
end;
I had to insert the statement with the comment "Memory leak without this" to avoid memory leaks. Any idea why the compiler does not free TerminateProc on its own? Is this a compiler bug?