Discussion:
TFPTimer memory leak
Add Reply
Okoba via fpc-devel
2018-09-25 18:31:47 UTC
Reply
Permalink
Hi,

I have a memory leak problem with TFPTimer and I think I'm missing something. It happens randomly and not always.
Tested with Lazarus 1.8.4 and FPC 3.0.4 and FPC 3.1.1 on last updated version of Windows 10 with Debug build mode and it writes a memory leak lead to "Driver.Enabled := True;"
Can anyone help me?

procedure TForm1.FormCreate(Sender: TObject);
begin
Driver := TFPTimer.Create(Self);
Driver.Interval := 33;
Driver.OnTimer := @DriveOnTimer;
Driver.Enabled := True;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
Driver.Enabled := False;
Driver.Free;
end;

procedure TForm1.DriveOnTimer(Sender: TObject);
begin
Caption := TimeToStr(Now);
end;

Heap dump by heaptrc unit
974 memory blocks allocated : 1698252/1700016
972 memory blocks freed : 1698116/1699880
2 unfreed memory blocks : 136
True heap size : 753664
True free heap : 753056
Should be : 753272
Call trace for block $00000000012AE390 size 16
$0000000100010CEB
$0000000100012D87
$0000000100012608
$000000010018985D
$0000000100189C59
$0000000100189622
$0000000100189551
$000000010003AA64 line 39 of unit1.pas
Call trace for block $000000000129E7B0 size 120
$0000000100010C12
$000000010000DF57
$00000001001897FA
$0000000100189C59
$0000000100189622
$0000000100189551
$000000010003AA64 line 39 of unit1.pas
$0000000100020591 line 939 of include/customform.inc
Okoba via fpc-devel
2018-09-28 14:53:02 UTC
Reply
Permalink
In this topic BrunoK said if we add Application.ProcessMessages; before Driver.Free it prevents the memory leak.
But I want to know if this is a good solution for it and if I faced a bug.

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
Post by Okoba via fpc-devel
Hi,
I have a memory leak problem with TFPTimer and I think I'm missing something. It happens randomly and not always.
Tested with Lazarus 1.8.4 and FPC 3.0.4 and FPC 3.1.1 on last updated version of Windows 10 with Debug build mode and it writes a memory leak lead to "Driver.Enabled := True;"
Can anyone help me?
procedure TForm1.FormCreate(Sender: TObject);
begin
Driver := TFPTimer.Create(Self);
Driver.Interval := 33;
Driver.Enabled := True;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Driver.Enabled := False;
Driver.Free;
end;
procedure TForm1.DriveOnTimer(Sender: TObject);
begin
Caption := TimeToStr(Now);
end;
Heap dump by heaptrc unit
974 memory blocks allocated : 1698252/1700016
972 memory blocks freed : 1698116/1699880
2 unfreed memory blocks : 136
True heap size : 753664
True free heap : 753056
Should be : 753272
Call trace for block $00000000012AE390 size 16
$0000000100010CEB
$0000000100012D87
$0000000100012608
$000000010018985D
$0000000100189C59
$0000000100189622
$0000000100189551
$000000010003AA64 line 39 of unit1.pas
Call trace for block $000000000129E7B0 size 120
$0000000100010C12
$000000010000DF57
$00000001001897FA
$0000000100189C59
$0000000100189622
$0000000100189551
$000000010003AA64 line 39 of unit1.pas
$0000000100020591 line 939 of include/customform.inc
Loading...