<p>Am 27.10.2014 17:20 schrieb "Hans-Peter Diettrich" <<a href="mailto:DrDiettrich1@aol.com">DrDiettrich1@aol.com</a>>:<br>
><br>
> Jonas Maebe schrieb:<br>
><br>
><br>
>> Additionally, as mentioned before, I still believe it's a very bad idea to be able to inherited from a regular class and turn it into a reference counted class. Reference counted and non-reference-counted<br>
>> classes are different language entities with different behaviour and different code generation requirements, and hence should be completely unrelated.<br>
><br>
><br>
> Something like ShortString and AnsiString?</p>
<p>With the difference that Short- and AnsiString are assignable to eachother while Jonas does not want that for reference counted and ordinary classes.</p>
<p>>> Even if you completely forbid typecasting a reference counted class into a non-reference-counted parent class, simply calling an inherited method from a non-reference-counted parent class can easily completely mess up the reference counting (e.g. suppose that inherited method inserts "self" into a linked list).<br>
><br>
><br>
> ACK. The only way out; I can see; is adding the *possibility* of refcounting to TObject, meaning Add/ReleaseRef methods and a RefCount field. Then the compiler can safely generate refcounting code for *all* objects and non-weak references, and the counting methods take care of required operations. Delphi offers two means for specialized refcounting, the virtual counting methods, and the (COM compatible?) refcount value of -1 for unmanaged objects.</p>
<p>What do you mean with "virtual counting methods"?<br>
The main reason I decided not to introduce reference counting for every class was that some people feared the performance impact of the reference counting. Though Florian said that it shouldn't be that bad on today's CPUs...<br>
That said: if someone wants to test it one could add "refcounted" to TObject (my code should(!) handle that correctly) and see what happens... (of course there will be problems with circular references then)</p>
<p>Regards,<br>
Sven</p>