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

noreply at z505.com noreply at z505.com
Wed Apr 12 14:32:12 CEST 2017


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.



More information about the fpc-pascal mailing list