[fpc-devel] Suggestion: reference counted objects

Gennady Agranov gennadyagranov at gmail.com
Sat Sep 20 22:54:01 CEST 2014


Hi,

I will address multiple previous e-mails on  this subject :)

1. FPC does perform reference counting if variable type is interface, 
but not if variable type is class that implements interface - 
legacy/compatibility reasons?

If you want to do ARC for objects - just remove this limitation and 
allow compiler to generate reference counting code not just for for 
interfaces but for classes that implement interface - AFAIK any 
interface in FPC/Delphi extends IUnknown and has reference counting methods.

2. I agree with Sven - adding reference counting to TObject is a bad idea

Please do not look at Delphi - they just follow Apple - and both 
companies do not address real issues with their development tool chains 
- it is all pure marketing.

In reality ARC and "weak" keyword do not magically solve the memory 
management issues - you either have GC or you do not have GC - there is 
no way around it.

I personally like TComponent approach - you have an object that owns 
other objects - as soon as this object dies - all children and 
grandchildren die too.

Combining it with ARC seems to me the way to go...

3. About "weak" attribute - current "strong" approach with interface 
reference has a contract - it is either nil or pointer to valid instance.
If you mark interface reference as "weak" - how do you know whether this 
not nil reference is valid or not - I can be missing something here - 
please explain.

In Java weak reference is accessed through some intermediate object and 
you can this object whether the reference is gone or is still valid - 
but you need to have GC to do it...

Regards,
Gennady






More information about the fpc-devel mailing list