FPC people claim that they can not reproduce problem with fpc from 2015-12-31 - rev. 32810.
bugs.freepascal.org/view.php?id=29297
Simple Memory Leak Program (I hope it helps).
Fresh install of CT560 on Windows 7 64 bit. CT560 is Win32.
program SimpleMemoryLeak;
{$mode objfpc}{$H+}
uses
cmem,
heaptrc, // Important - Uncheck / Project Options / Debugging / Use HeapTcr unit
lineinfo, // Important - Uncheck / Project Options / Debugging / Dispaly line numbers ....
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Interfaces, Classes, SysUtils,
DateUtils;
procedure SimpleLeak;
var MyS: String;
MyPchar1: PChar;
MyString: String;
begin
MyString := 'TestString';
MyPChar1 := PChar(MyString);
SetString(MyS, MyPChar1, Length(MyString));
//MyS := ''; this line is needed for CT570 to avoid leak. It is not needed for CT540
SetString(MyS, MyPChar1, Length(MyString) - 5);
// MyS := Copy(MyS, 1, Length(InString) - 5);
end;
{$R *.res}
begin
if FileExists('.\heaptrc.trc') then DeleteFile('.\heaptrc.trc');
heaptrc.printfaultyblock := True;
heaptrc.printleakedblock := True;
heaptrc.quicktrace := True;
heaptrc.HaltOnNotReleased := True;
heaptrc.SetHeapTraceOutput('.\heaptrc.trc');
Writeln('');
Writeln('*********************************************');
Writeln('');
Writeln('SetString Leak');
SimpleLeak;
Writeln(' ');
Writeln('Finish, you can find the output data in file :');
Writeln('../xbin/heaptrc.trc');
Writeln('Hit any key to exit... After that check heaptrc.trc for leaks.');
Readln;
end.
HeapTrc Result is:
G:\temp\xbin\SimpleMemoryLeak.exe
Heap dump by heaptrc unit
263 memory blocks allocated : 8425/8936
262 memory blocks freed : 8402/8912
1 unfreed memory blocks : 23
True heap size : 196608 (96 used in System startup)
True free heap : 196416
Should be : 196424
Call trace for block $01767B18 size 23
Block content: 00000100010000000A00000054657374537472696E6700 -
Tes Str
$00402CC2
$00402DF0
Regards, Dinko