Re: [fpc-pascal] sqldb create/free lifetime of object
Am 12.04.2017 14:32 schrieb: > In a way, this is a form of garbage collection or RAII sort of. And reduces the obnoxious free's required in non garbage collected programming languages... So it's a nice feature/trick to have ownership. But at the same time you can think there is a memory leak since there is no create/free pair easily visible... > > So you train your eyes to look for ownership. > > And similarly, delphi gui widgets you throw onto a form, don't need to be freed yourself, even though the program created them - so in a way delphi TForm's gui widgets are also garbage collected, sort of. Again a nice feature/trick to avoid all the obnoxious free calls that bloat up the source code with line noise. Both are in fact using the same mechanism as you can put e.g. a TSQLTransaction on a form as well. Regards, Sven ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] sqldb create/free lifetime of object
On 2017-04-12 05:03, LacaK wrote: Yes, example should be adjusted. Please report bug to not forget. Thanks -Laco. It is not a bug, I just wanted to clarify the magic going on behind the scenes - which, is "ownership". That's all I needed to know. The key to seeing this trick/magic is in the Create function where you pass in the C (connection) as the owner. But on my cell phone I didn't really see this, and, it's not always obvious.. hence my gripe. In a way, this is a form of garbage collection or RAII sort of. And reduces the obnoxious free's required in non garbage collected programming languages... So it's a nice feature/trick to have ownership. But at the same time you can think there is a memory leak since there is no create/free pair easily visible... So you train your eyes to look for ownership. And similarly, delphi gui widgets you throw onto a form, don't need to be freed yourself, even though the program created them - so in a way delphi TForm's gui widgets are also garbage collected, sort of. Again a nice feature/trick to avoid all the obnoxious free calls that bloat up the source code with line noise. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] sqldb create/free lifetime of object
Yes, example should be adjusted. Please report bug to not forget. The example is correct. All objects are freed. No need for a bugreport. Yes, correct. -Laco. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] sqldb create/free lifetime of object
On Wed, 12 Apr 2017, LacaK wrote: Yes, example should be adjusted. Please report bug to not forget. The example is correct. All objects are freed. No need for a bugreport. Michael. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] sqldb create/free lifetime of object
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. ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Re: [fpc-pascal] sqldb create/free lifetime of object
Yes, example should be adjusted. Please report bug to not forget. Thanks -Laco. 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. P.s. how is it freed magically? Sorry I am on cell phone and cannot look at source easily to find out 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 ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal