ORM and preventing memory leaks

Home Forums kbmMW ORM and preventing memory leaks

Viewing 1 reply thread
  • Author
    Posts
    • #57090
      mrluigi2017
      Participant

      Hi,

      In my application I have the following code:

      Requirement := TPMRequirement.Create;
      try

      Requirement.PMItem := Orm.FromDataset<TPMItem>(FItemTable, True, True);
      Requirement.RequirementItem := Orm.FromDataset<TPMRequirementItem>(FDetailTable, True, True);

      Because the constructor of the TPMRequirement instanciates both PMItem and RequirementItem the PMItem and RequirementItem should be freed before getting the value from the ORM else you will have a memory leak. To accomplish this I have added the following code:

      procedure TPMRequirement.SetPMItem(const Value: TPMItem);
      begin
      FPMItem.Free;
      FPMItem := Value;
      end;

      After adding this code I got a Invalid Pointer Exception but I don’t understand why. I have tested similar code without kbmmw/orm and it just works fine. If I free the both items before the ORM code is called it works fine, but that solution is a bit uggly.

      Any suggestions/best practice?

       

    • #57171
      kimbomadsen
      Keymaster

      Well… one thing might be that the initial free is running on a bad pointer.
      But it would be helpful to see how the definition of TPMItem and TPMRequirementItem actually is.

      /Kim

Viewing 1 reply thread
  • You must be logged in to reply to this topic.