TZQuery memory issues (possible leaks)
Posted: 10.01.2015, 17:25
Lazarus 1.2.6+ZEOSDBO-7.1.4+PostgreSQL
Consider simple project (code below).
With TZReadOnlyQuery application memory usage after open/close cycles is the same (don't grows).
With TZQuery application memory usage grows with each open/close cycle and I can't find any way to free that memory.
There is the same issue if I create/free all objects dynamically in the code.
See screenshots in attachments:
before ZQuery1.Open - 19640K (1-zquery-before-open.PNG)
after ZQuery1.Open - 34224K (2-zquery-after-open.PNG)
after DBGrid1.DataSource := DataSource1 - 58020K (3-zquery-after-datasource.PNG)
after ZQuery1.Close - 22729K (4-zquery-after-close.PNG)
With TZQuery, for example, after 3 open/close cycles I have 46288K memory usage instead of the initial 19640K or about.
Unlike TZReadOnlyQuery with TZQuery there is additional memory grows on execution of
Consider simple project (code below).
With TZReadOnlyQuery application memory usage after open/close cycles is the same (don't grows).
With TZQuery application memory usage grows with each open/close cycle and I can't find any way to free that memory.
There is the same issue if I create/free all objects dynamically in the code.
See screenshots in attachments:
before ZQuery1.Open - 19640K (1-zquery-before-open.PNG)
after ZQuery1.Open - 34224K (2-zquery-after-open.PNG)
after DBGrid1.DataSource := DataSource1 - 58020K (3-zquery-after-datasource.PNG)
after ZQuery1.Close - 22729K (4-zquery-after-close.PNG)
With TZQuery, for example, after 3 open/close cycles I have 46288K memory usage instead of the initial 19640K or about.
Unlike TZReadOnlyQuery with TZQuery there is additional memory grows on execution of
Code: Select all
DBGrid1.DataSource := DataSource1
Code: Select all
unit zquery_main;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, db, FileUtil, Forms, Controls, Graphics, Dialogs,
DBGrids, StdCtrls, ZConnection, ZDataset;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
ZConnection1: TZConnection;
ZQuery1: TZQuery;
ZReadOnlyQuery1: TZReadOnlyQuery;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
ZConnection1.HostName:='192.168.0.8';
ZConnection1.Protocol:='postgresql-9';
ZConnection1.Database:='du';
ZConnection1.User:='du_admin';
ZConnection1.Password:='du_admin';
ZConnection1.UseMetadata:=false;
ZConnection1.AutoCommit := false;
ZConnection1.Connect;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
DataSource1.DataSet := ZQuery1;
ZQuery1.Connection := ZConnection1;
ZQuery1.SQL.Clear;
ZQuery1.SQL.Add('select * from contracts;');
ZQuery1.Prepare;
ZQuery1.Open;
DataSource1.DataSet := ZQuery1;
DBGrid1.DataSource := DataSource1;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
ZQuery1.Close;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
DataSource1.DataSet := ZReadOnlyQuery1;
ZReadOnlyQuery1.Connection := ZConnection1;
ZReadOnlyQuery1.SQL.Clear;
ZReadOnlyQuery1.SQL.Add('select * from contracts;');
ZReadOnlyQuery1.Prepare;
ZReadOnlyQuery1.Open;
DataSource1.DataSet := ZReadOnlyQuery1;
DBGrid1.DataSource := DataSource1;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
ZReadOnlyQuery1.Close;
end;
end.