[Lazarus] IUnknown and reference counting

Hans-Peter Diettrich DrDiettrich1 at aol.com
Mon Mar 25 13:03:59 CET 2013


Graeme Geldenhuys schrieb:
> On 2013-03-21 20:48, Hans-Peter Diettrich wrote:
>> Sven Barth schrieb:
>>> On 21.03.2013 21:14, Hans-Peter Diettrich wrote:
>>>> Sven Barth schrieb:
>>>>
>>>>>  > Thanks for giving me insight into the crippled implementation of
>>>>> interfaces in FPC :-]
>>>>>
>>>>> Why crippled?
>>>> When FPC does not allow to use delegation ("implements") together with
>>>> implementing selected methods, this feature is of no practical use :-(
>>> There exists at least a bug report about it: 
>>> http://bugs.freepascal.org/view.php?id=16531 :)
>> +1
>>
>>>> Also the hype about CORBA interfaces looks like mere eye-candy or
>>>> obfuscation to me. Delphi interfaces require neither COM nor CORBA, they
>>>> are only open in either direction.
>>> But some people don't like the reference counting. They want to use 
>>> interfaces like in other languages to just define a "interface" to a class.
>> Since reference counting must be implemented,
> 
> Why *must* reference counting be implemented when you want to use
> Interfaces? Many other languages also have interfaces with no reference
> counting.

Other languages use different memory management (mark-sweep), where 
Delphi uses reference counting. Ignoring this difference is comparing 
apples with oranges.


> I don't need reference counting just to have interfaces support -
> so based on what you say, reference counting must be forced upon me!

Your code may work without reference-counted interfaces, but other code 
may not, in detail when imported from other languages. So implementing 
the reference counting methods IMO is the safe way, not using it should 
be reserved for experts.

> And I must do more work in my class by adding IUnknown to the TMySuperClass too.

Dunno whether this is required for bare Delphi interfaces. Reference 
counting does not require IUnknown, as can be seen with dynamic arrays 
and strings.

DoDi





More information about the Lazarus mailing list