[fpc-devel] Redefine FillChar() to use out parameter instead
jonas.maebe at elis.ugent.be
Thu Nov 19 22:49:27 CET 2009
On 19 Nov 2009, at 22:31, Florian Klaempfl wrote:
> Because a VAROUT parameter would be simply overwritten by the callee
> even if it contains a valid automated type:
> procedure p(varout v : ansistring);
I don't think that this could cause a memory leak, otherwise this would cause two memory leaks:
procedure p(varout v : ansistring);
The fact that v is a varout would simply mean that it would not be finalized before the call. It wouldn't necessarily mean that reference counting would no longer be applied inside the callee. Just like with regular "out" parameters the compiler inside the callee still calls FPC_DECR_REF* on the out parameter every time you assign something to it, even though it's finalized before the call.
What would cause a memory leak, is this:
procedure clear(varout v; size: ptruint);
s : string;
But that's the same with "var".
More information about the fpc-devel