AccessViolation releasing Entities

We are using associations within dynamic properties and we run into access violations by releasing objectmanagers within TDynamicProperties.Destroy.

This occurs because mapped object is released by manager before TDynamicProperties.Destroy is called, so you got hanging pointers right there.

We are using FastMM, that will fetch this error, just as a marker, if you could not reproduce this issue.

I could set reference to nil by myself but I think, you should take care of this.

Are you able to consistently reproduce this issue? If yes, I can try to send you a modified version of TDynamicProperties to see if it can solve your problem.

it would work if TDynamicProperties.Destroy would look like this:

destructor TDynamicProperties.Destroy;
var
  Prop: TValue;
begin
  // Destroy dynamic properties that are lists.
  for Prop in FProps.Values do
    if Prop.IsObject and not Prop.IsEmpty and Bcl.Collections.IsObjectList(Prop.TypeData.ClassType) then
      Prop.AsObject.Free;
  FProps.Free;
  inherited;
end;

I could reproduce this issue most times, but not in every try...
What do you think about this fix?

Yes, that is a valid fix. We will include it.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.