[fpc-devel] Reference counting interface objects
Jonas Maebe
jonas.maebe at elis.ugent.be
Thu Oct 16 17:13:35 CEST 2014
On 16 Oct 2014, at 16:43, Adriaan van Os wrote:
> Jonas Maebe wrote:
>
>> No, it won't:
>> 1) if the external code expects it to be "out" and you declare it
>> as "var": the caller will decrease the reference count and the
>> ppEvent that you get will have as initial value "nil". You can just
>> assign to it like normal.
>> 2) if the external code expects it to be "var" and you declare it
>> as "out": the caller will not do anything and hence the ppEvent
>> will not be nil. However, assignments to the "out" parameter still
>> cause its reference count to be decreased. After all, you can
>> assign multiple times to an "out" parameter, so the compiler cannot
>> assume it's already nil. The only problem that could happen here is
>> if you would explicitly write your code in a way that behaves
>> differently depending on whether the initial value is nil (e.g.,
>> assigning something to it only in one branch of an if-statement,
>> and then later checking whether it's "still" nil to determine
>> whether you have to assign something else to it).
>
> Sorry, but the above explanation flabberghasts me.
I explained the opposite scenario as you: calling a method implemented
in Pascal from external Windows code (with mismatched var/out
modifiers). Rereading your message, that's indeed not what you were
talking about.
In general, using wrong/mismatched modifiers when importing routines
virtually always causes problems though (and often much worse than
just a memory leak), there's nothing special about reference counted
types here.
Jonas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20141016/95d31023/attachment.html>
More information about the fpc-devel
mailing list