[Lazarus] IUnknown and reference counting
Kostas Michalopoulos
badsectoracula at gmail.com
Thu Mar 21 15:15:11 CET 2013
Ah, ok thanks for the explanations.
On Thu, Mar 21, 2013 at 2:54 PM, Sven Barth <pascaldragon at googlemail.com>wrote:
> Am 21.03.2013 14:48, schrieb Kostas Michalopoulos:
>
> Thanks, i understand that. My question is, can i somehow make FPC to add
>> AddRef/Release calls also to TBlah so i can use refcounting with a class
>> just like i would use it with an interface?
>>
>
> No. At least not yet (when a new Delphi is released which might be
> featuring reference counted objects than this is up for discussion again)
>
>
> Is there some technical limitation on why this is only done with
>> interfaces and not all objects that descend from a refcounted interface?
>>
>>
> It's more a logical problem. Assume you have a "TInterfacedObject" which
> you put into a variable "intf" of type "TInterfacedObject". As long as you
> use only "intf" there won't be any problem. But once you assign the value
> of "intf" to e.g. a variable "obj" of type "TObject" you'll have a problem,
> because the compiler does not know that "obj" contains a variable of type
> "TInterfacedObject" and thus the compiler can not create any reference
> counting calls. This way you would (depending on the situation) either
> create a memory leak or the interface would be freed before you stopped
> using the instance stored in "obj". So this situation is basically the same
> as we have today with the difference that we can now clearly say when
> reference counting will be applied and when not: if the variable is a (COM)
> interface then reference counting will be applied, otherwise it won't.
>
>
> Regards,
> Sven
>
> --
> ______________________________**_________________
> Lazarus mailing list
> Lazarus at lists.lazarus.**freepascal.org<Lazarus at lists.lazarus.freepascal.org>
> http://lists.lazarus.**freepascal.org/mailman/**listinfo/lazarus<http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20130321/914f014d/attachment-0003.html>
More information about the Lazarus
mailing list