[fpc-devel] Managed Types, Undefined Bhaviour
Michael Van Canneyt
michael at freepascal.org
Fri Jun 29 14:41:41 CEST 2018
On Fri, 29 Jun 2018, Martok wrote:
> Am 29.06.2018 um 12:43 schrieb Michael Van Canneyt:
>> Out of curiosity, can you give a simple example of such a funny behaviour
>> in such a chaining pattern ?
> We've had this topic about 2 years ago with regard to automatic file close on
> interface release. Interestingly, something must have changed in the mean time,
> because the trivial testcase is now *different* , which is somewhat the point of
> being weird-undefined ;-)
> Take this example: https://pastebin.com/gsdVXWAi
> The tempvar used to get reused, causing lifetime issues with the "chain object".
> This isn't the case anymore, now three independent tempvars are used, all of
> which live until the end of the function, potentially keeping the object alive
> for a long time.
> There is also one fpc_intf_assign with associated addref/release per as
> operator, which isn't technically necessary.
> One could probably avoid the interfaces here with ARC records, but either I'm
> missing something or the scope lifetime of tempvars there is even worse.
What is the expected output of this program ?
As far as I can see, you get 2 chain and 1 done call. Which is what I'd expect.
The overrides of the _* calls are useless, since they are not virtual in
TInterfacedObject and hence never called. So that's OK too.
There is no memory leak, output is the same with 2.6.4 and 3.0.4 and trunk,
so what does this demo actually demonstrate other than that the code just
More information about the fpc-devel