Search code examples
delphimemory-leaksfiredac

Memory leak while defining a firedac connection


I have created a pooled connection using firedac, placing FDServerManager FDWaitCursir and FDphysMySQLDriverlink on a datamodule and on DataModuleCreate I have written a method that reeds a file named conn.ini

procedure TDataModule2.DataModuleCreate(Sender: TObject);
var
  oParams : TStringList;
  cdir, fname : string;
  fs : TFileStream;
  sr : tStreamReader;
 begin
   cdir := GetCurrentDir;
   fname := 'conn.ini';
   try
     fs := TFileStream.Create(cdir+TPath.DirectorySeparatorChar+fname, fmOpenRead);
     try
       sr := tStreamReader.Create(fs, TEncoding.UTF8);
       try
         oParams := TStringList.Create;
         while not sr.EndOfStream do
           oParams.Add(sr.ReadLine);
         FDManager1.AddConnectionDef('MySQL_pooled', 'MySQL', oParams);
       finally
         sr.Free;
       end;
     finally
       fs.Free
     end;
   except
      on E: EFileStreamError do
         showmessage('file not found '+e.Message);
   end;
end;

the ini file

[MySQL_pooled]
Server=localhost
User_Name=franz
Password=franz
Database=mydb
Pooled=false
POOL_MaximumItems=100

I prepared a form for testing the connection

procedure TForm1.bnConnectClick(Sender: TObject);
begin
   DataModule2.FDConnection1.ConnectionDefName := 'MySQL_pooled';
   DataModule2.FDConnection1.Connected := true;
   ShowMessage('OK')
end;

the connection is OK but whet i close the application I receive a memory leak Memory leak screenshot

but i don't know why. Any suggestion?


Solution

  • It seems like you don't destroy oParams.