First let's say ZeosLib is a wonderfull product. I've been examining the code of the library and I'am a little bit confused. I want to use
Code: Select all
TZAbstractStatement
Code: Select all
TZAbstractResultSet
of interfaces.
The question:
Will the folowing code produce a memory leak.
Code: Select all
var
FZConn: TZConnection;
FZStat: IZStatement;
FZResSet: IZResultSet;
begin
// create the database connection
FZConn := TZConnection.Create(nil);
FZConn.Properties.Text := ADBConnStr;
FZConn.Connect;
// create statement and execute query
FZStat := FZConn.DbcConnection.CreateStatement;
FZResSet := FZStat.ExecuteQuery(ASQL);
// do some processing
...some code...
...some code...
// finally we can't realy destroy FZStat and FZResSet since they are
// interfaces so we are left only with destroying the TZConnection
FZConn.Disconnect;
FZConn.Free;
end;
From the library code it is obvious that
Code: Select all
TZConnection
Code: Select all
FZConn.DbcConnection.CreateStatement
descendant of
Code: Select all
TZAbstractStatement
Code: Select all
TZAbstractStatement
Code: Select all
IZStatement
Code: Select all
FZConn.DbcConnection.CreateStatement
an interface
Code: Select all
IZStatement
Code: Select all
TZAbstractStatement
not dispose the allocated resources for the created statement instance since no link can be established from the interface to the statement (maybe I'am wrong here).
Everything would be ok if the
Code: Select all
TZConnection
can see it doesn't do that(maybe I'am wrong again).
another question:
Is there a way by which we can create a specific
Code: Select all
TZAbstractStatement
instances(specific to a RDBMS) and return a reference to that instance.
I know that I can do that the hard way by coding, checking
the protocol, but is there a faster way already implemented inside the library.
Thanks in advance. Looking forward to your answers.