[fpc-devel] ref count issue with out param

Martin Frb lazarus at mfriebe.de
Sat Jun 13 16:17:21 CEST 2015

On 13/06/2015 15:12, Michael Van Canneyt wrote:
> Note the 0 !
> Secondly, the section about 'out' parameters is very old; there were 
> not nearly so much managed types at the time.
> I will update it, I was just documenting the new string types anyway. 
> The above will nicely illustrate the point.

What about the (unverified) remark on the forum that delphi does it 
different (apparently passing nil in that case)?

"const" is an exception. The purpose of const is to skip the ref counting.

"Out" has a different purpose. Should it really create a dangling 
pointer in a ref counted variable?

In your example you are lucky you got a refcount of 0. The memory is 
after-all freed. you called the StringRefCount on a dangling pointer. 
Anything could have happen.

More information about the fpc-devel mailing list