[fpc-devel] Suggestion: reference counted objects

Peter Popov ppopov99 at gmail.com
Sat Sep 20 13:11:10 CEST 2014


Please do not reference count TObject. This is a uniquely bad and  
unnecessary idea. I will switch to ANSI C if you guys do it

Peter


On Sat, 20 Sep 2014 13:52:57 +0300, Sven Barth  
<pascaldragon at googlemail.com> wrote:

> On 20.09.2014 12:36, Hans-Peter Diettrich wrote:
>> Fabrício Srdic schrieb:
>>> Hello,
>>>
>>> In platforms with managed code (.NET, Java), objects are automatically
>>> freed by the memory manager / garbage collector.
>>>
>>> Would not it be interesting to have a similar feature in FPC?
>>
>> 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:
>
> === code begin ===
>
> somestrlist.AddObject('Foobar', TObject(42));
>
> === code end ===
>
> And also there's the problem of cycles especially considering the LCL  
> where each TControl has an owner and a list of child components.
> And then there's of course the dealing with existing code:
>
> === code begin ===
>
> o := TObject.Create;
> try
>    // something
> finally
>    o.Free;
> end;
>
> === code end ===
>
> 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.
>
> Regards,
> Sven
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel



More information about the fpc-devel mailing list