Skip to content

Finish heaptrc to-free queue before reporting leaks.

See this thread and, more importantly (the thread can make you think the issue is somehow related to external threads etc.), try running this with -gh (Use heaptrace unit):

{$mode objfpc} {$modeswitch anonymousfunctions}
var
	th: TThreadID;
	p: pointer;
begin
{$if not declared(UseHeapTrace)} {$error enable heaptrc please thanks} {$endif}
	th := BeginThread(
		function(param: pointer): PtrInt
		begin
			p := GetMem(1000);
			result := 0;
		end);
	WaitForThreadTerminate(th, 0);
	CloseThread(th);

	FreeMem(p);
	// FreeMem(GetMem(0));
	DumpHeap;
end.

You should get either a false leak report which disappears after uncommenting FreeMem(GetMem(0)) or (for me: after replacing 1000 with 100 o_O) a crash which disappears the same way; person from the forum got this crash, too. I didn’t study how heaptrc works (if I studied it, I’d rewrite the hell out of it, it's sometimes unusably slow and definitely shouldn’t require special treatment like -gh) (while we at it: merge !659 (merged) which is a heaptrc QoL for GUI apps??), but finishing the to-free queue before DumpHeap, which is the side effect of FreeMem(GetMem(0)), seems to fix both cases (even if there were actual leaks).

Edited by Rika

Merge request reports

Loading