After replacing the AnsiString type types with TBytes (a string array) using the ToBytes method (see below), Delphi reported no memory leaks - Free Pascal 2.6.2, however, it shows a leak if the TBytes value is passed to a method with a parameter of type Pointer .
The following memory leak code:
program project1; {$mode delphi} uses SysUtils; function ToBytes(const AValue: AnsiString): TBytes; begin SetLength(Result, Length(AValue)); // <-- leak (ine 10) if Length(AValue) > 0 then Move(AValue[1], Result[0], Length(AValue)); end; procedure Send(P: Pointer); begin end; begin Send(ToBytes('test')); SetHeapTraceOutput('heaptrace.log'); end.
Memory Leak Report:
Call trace for block $001C5CC0 size 12 $00401586 TOBYTES, line 10 of project1.lpr $00401622 main, line 21 of project1.lpr
If I change the send method to accept an argument of type TBytes, the memory leak will disappear.
memory-leaks freepascal compiler-bug fpc
mjn
source share