[fpc-devel] FreeNotification and opRemove
lazarus at mfriebe.de
Thu Mar 8 10:56:37 CET 2012
I found a behaviour, of which I am not sure, if it is intended. Maybe
someone can comment
My understanding is that FreeNotification are *always* set up
will set up for C1 to inform C2, and for C2 to inform C1 whichever is
destroyed first to call the other
will remove both.
It will lead to C2 removing C1 from it's list of FreeNotifies, but C1
will keep C2 on the list.
If then C2 is destroyed, it does not inform C1 about that, and C1 ends
up with a dangling pointer to the no longer existing C2.
Destroying C2 will then crash.
In the example below (compile with -gt) opRemove is caused by
It crashes on the last line.
I was briefly wondering, if in case C1 did call
"C1.FreeNotification(c2);", then C1 should overwrite Notification and
check for the opRemove and call "RemoveFreeNotification" itself?
But if that was the case, then why does TComponent interfer with the
FreeNotify list at all?
Owner, C1, C2: TComponent;
Owner := TComponent.Create(nil);
C1 := TComponent.Create(Owner);
C2 := TComponent.Create(Owner);
Owner.RemoveComponent(C1); // C2 Gets on opRemove
C1.Free; // crash
More information about the fpc-devel