[fpc-pascal] Re: operator overloading and counting references / creating / destoying anonymous instances

Florian Klämpfl florian at freepascal.org
Fri Jul 29 18:34:36 CEST 2011


Am 29.07.2011 12:00, schrieb Bernd:
> I have run across another even more severe problem: Although using
> reference counted interfaces makes everything work without memory
> leaks there is one problem that gives all the nice syntactic sugar a
> really bad taste:
> 
> A := B
> 
> I am not allowed to overload the assignment of equal types. This means
> in the above I would have created a reference to B instead of a copy.
> If I now do an operation on A that does *not* create a new instance of
> it I will also change the value that B is pointing to, so I am
> *forced* to make new instances even if I could in some cases easily
> avoid them. 

No. Just check the ref. count if you plan to do an operation on A: if
it's >1, create a copy for A and operate on the copy.



More information about the fpc-pascal mailing list