[yunqa.de] Re: TDISQLite3Statement memory leak?

  • From: Delphi Inspiration <delphi@xxxxxxxx>
  • To: yunqa@xxxxxxxxxxxxx
  • Date: Mon, 07 Jul 2008 09:59:06 +0200

Clyde England:

>Yes, as per my oroiginal post I already did this. Please see my comment that 
>reads "Interestingly if I substitute stmt.close with stmt.free I don't get the 
>memory leak, but I have never seen any examples that explicitly call the free 
>method like this and am concerned this may cause other issues"

You do not see a call to TDISQLite3UniDirStatement.Free in the demos because 
they use TDISQLite3UniDirStatement dropped on a form. This means that Delphi 
automatically creates and destroys its instances during application start-up 
and shut-down. This supersedes calls to Create and Free.

>So can you please elaborate on:
>
>1. Are there any known issues with using the free method rather than close

There are no known issues with TDISQLite3UniDirStatement.Free. Like with other 
Delphi objects, Free is the recommended method to dispose of the object and 
release its memory.

>2. Everthing I have in these lists seems to refer to the close method, so 
>shouldn't that be the correct way to finalyze things and clean up memory?

No. Each call to TDISQLite3Database.Prepare[16] returns a new instance of 
TDISQLite3UniDirStatement which must consequently be freed. Failing to do so 
results in a memory leak, which you experienced in your code.

TDISQLite3UniDirStatement.Close = TDataSet.Close

Quote from the Delphi help: "Call Close to set the Active property of a dataset 
to false. When Active is false, the dataset is closed; it cannot read or write 
data and data-aware controls can?t use it to fetch data or post edits."

TDISQLite3UniDirStatement.Free = TObject.Free

Delphi help: "Use Free to destroy an object. Free automatically calls the 
destructor if the object reference is not nil. Any object instantiated at 
runtime that does not have an owner should be destroyed by a call to Free so 
that it can be properly disposed of and its memory released."

As implemented in TDISQLite3UniDirStatement, Free automatically calls Close, so 
you are save to call just Free.

Ralf 

_______________________________________________
Delphi Inspiration mailing list
yunqa@xxxxxxxxxxxxx
//www.freelists.org/list/yunqa



Other related posts: