Maybe memory leak when using DbcConnection.CreateStatement
Posted: 13.12.2005, 02:38
Hi, all.
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 and descendants in my application. The ZeosLib makes havy use
of interfaces.
The question:
Will the folowing code produce a memory leak.
The comment:
From the library code it is obvious that instances adapt their selfs to the RDBMS system and
creates a
descendant of which is specific to the RDBMS. implements the interface. Now the problem is that the result from is
an interface, rather then a reference to the created specific descendant instance. After using the interface you can
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 instance kept track of all the statements it created and freed resources when needed (maybe using a GarbageCollector) but as much as I
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 descendant
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.
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.