I suspect that a double-free error leads to an access violation (later in the same program).
The given class contains a Generic TDictionary and assigns a ChangeNotification handler after creating it using FMyDict.OnValueNotify := ChangeNotification;
procedure TMyClass.ChangeNotification(Sender: TObject; const Item: TMyValueType; Action: TCollectionNotification);
begin
if Action = cnRemoved then begin
Item.Free;
end;
end;
If I uncomment the Item.Free, the AV does no longer occur.
But because the AV appears sporiadically (once in several hundreds of loop iterations in the program) I can't exactly prove that there is a double free situation.
My first idea is to set some "marker" in the object before freeing it. On the second free I could see that this marker is set.
Or is there a different "best practice" for detection of a double-free?