On 14 Sep 2011, at 23:17, Marcos Douglas wrote:

BUT, if I create my TFoo without refcount should works, right?

Only in some circumstances. These circumstances depend on when the compiler allocates temporary interface instances, and when these are finalized.

... but, does not work. In Delphi 7 yes, but no in FPC.

It also "works" in FPC if you remove heaptrc. What happens is
a) the compiler creates a temporary copy of the interface instance at some point in the code b) you free the underlying object and heaptrc overwrites its memory with 0xf0f0f0f0 c) at the end of the routine, the compiler tries to finalize the temporary interface instance. This crashes because the interface instance no longer contains valid data

Without heaptrc, the example happens to work because the freed memory of the instance hasn't been reallocated and overwritten yet. It's not safe in general though.

The answer is: the hack with returning -1 from _AddRef and _Release, while documented by Embarcadero, is unsafe because it depends on implementation details. Do not use it. Instead, if you do not want reference-counted interfaces, use {$interfaces corba} instead as mentioned earlier in this thread.


Jonas

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

Reply via email to