[fpc-pascal] sqldb create/free lifetime of object

Michael Van Canneyt michael at freepascal.org
Wed Apr 12 14:11:16 CEST 2017



On Wed, 12 Apr 2017, Lars wrote:

> The sql query object and transaction object are created but not freed:
>
> http://www.freepascal.org/docs-html/fcl/sqldb/usingsqldb.html
>
> I think the docs should mention that the objects need not to be freed, as
> this violates normal programming practice of freeing all objects you
> create.

They must of course be freed. They ARE freed.

>
> P.s. how is it freed magically? Sorry I am on cell phone and cannot look
> at source easily to find out

All three classes are components.
Q and T are owned by C. When C is freed, Q and T are freed.

>
> This is one gripe I have with programming is that you never really know if
> something should be freed just by looking at the code. If it is not freed
> and it was created by you it is a good indication its a mem leak, but not
> if there is magic behind the scenes to free it automatically

There is no magic other than standard TComponent owner/owned functionality.

Michael.



More information about the fpc-pascal mailing list