TMemDataset freeing memory lazarus / 16-Databases ---------------------------------------------------------------------- brick08 · 2022-02-09 01:56 i use stable Lazarus 2.2.0, FPC 3.2.2 for Win32 when TMemDataset is destroyed, a memory leak error appears. I compile with Use heaptrc (-gh). Test project in attach. Does anyone reproduce this error? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  mds: TMemDataSet;begin  mds := TMemDataSet.Create(Self);  try    mds.Clear(True);    TFieldDef.Create(mds.FieldDefs, 'id', ftInteger, 0, False, 0);    TMemDataSet(mds).CreateTable;    mds.Open;    mds.Append;    mds.FieldByName('id').AsInteger:=1;    mds.Post;  finally    mds.Free;   //in this line error  end; ---------------------------------------------------------------------- Handoko · 2022-02-09 02:43 That should be: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Button1Click(Sender: TObject);var  mds: TMemDataSet;begin  mds := TMemDataSet.Create(Self);  try    mds.Clear(True);    mds.FieldDefs.Add('id', ftInteger, 0, False);    mds.CreateTable;    mds.Open;    mds.Append;    mds.FieldByName('id').AsInteger:=1;    mds.Post;  finally    mds.Free;  end;end; ---------------------------------------------------------------------- brick08 · 2022-02-09 03:30 ok, it's right In module memds in procedure TMemDataset.CopyFromDataset(DataSet: TDataSet; CopyData: Boolean);  there is line: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i TFieldDef.C reate(FieldDefs,F.FieldName,F.DataType,F.Size,F.Required,F.FieldNo);al so lead to errors for me. Can you check it? ---------------------------------------------------------------------- Handoko · 2022-02-09 03:51 I do not use it, but I found this work for me: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i     TFieldDef.Create(mds.FieldDefs, 'id', ftInteger, 0, False, 1); Maybe the last parameter should start from 1. ---------------------------------------------------------------------- brick08 · 2022-02-09 06:19 i think it would be better to change this line in the module memds, because many TField.FieldNo started from 0, which leads to the error. Am I right?