[fpc-devel] Suggestion: reference counted objects

Hans-Peter Diettrich DrDiettrich1 at aol.com
Sat Sep 20 16:25:34 CEST 2014


Sven Barth schrieb:
> On 20.09.2014 12:36, Hans-Peter Diettrich wrote:

>> AFAIK some Delphi XE made TObject itself managed, by reference counting.
>> It would be easy to introduce the same feature in FPC, so that no
>> special base class would be required. Like with extended RTTI a decision
>> should be made, whether managed objects should be enabled or disabled by
>> default. Afterwards automatic management can be turned on or off for
>> every single class or object individually.
> 
> It's basically easy, yes, but then one has to deal with code like this:
[...]
> Which could lead to some unintended side effects if "o" is passed to 
> some other code which keeps the instance around and ".Free" merely 
> decreases the reference count. Of course that would have been a memory 
> leak before and now it's not, but nevertheless it changes behavior.

I already mentioned that destructors still are required, but will have 
an different purpose and usage than before. This would discourage 
continued use of Destroy(), BeforeDestruction() etc., which should at 
least be renamed to prevent unconverted legacy code from compiling. This 
change already will break compatibilitiy, so that consequently all 
libraries (in detail when dealing with lists containing objects) have to 
be updated. I was aware of such consequences, but I'm no more sure of 
the consequences of my idea of simply turning refcounting on or off for 
specific objects or classes.

The mere implementation of refcounting for TObject is easy, but the 
consequences are hell :-(

DoDi




More information about the fpc-devel mailing list