[Lazarus] Unicode branch
Hans-Peter Diettrich
DrDiettrich1 at aol.com
Sun Jun 30 18:25:11 CEST 2013
Marco van de Voort schrieb:
> On Sat, Jun 29, 2013 at 08:47:37PM -0400, waldo kitty wrote:
>>> (Some versions of?) Delphi deallocate interfaces at the end of a block of
>>> procedures, not immediately after first usage.
>> first usage or last usage?
>
> Last usage of course, sorry.
I'm somewhat confused now. When an object has an definite "last use", it
should not matter when it is destroyed afterwards, sooner or later.
A problem I could imagine were a refcount dropping to zero *before* that
reference is stored in another variable. E.g. in
intfvar := intfvar;
it will be a bad idea to _Release the old reference stored in the
intfvar variable while the same reference is kept in a register or
stack, before assigning the new reference to the variable. This is a
known aliasing problem, which must be solved properly by every compiler.
I'd solve it this way (compiled code):
//tempvar added by the compiler
tempvar := intfvar; //intfvar.AddRef
intfvar := newvalue; //intfvar._Release; newvalue.AddRef;
tempvar := nil; //here or on exit from the subroutine or code block
Another solution could use the property setter pattern:
if value <> newvalue then value := newvalue;
DoDi
More information about the Lazarus
mailing list