ORM memory confusion

Home Forums kbmMW ORM memory confusion

Viewing 2 reply threads
  • Author
    Posts
    • #54185
      mrluigi2017
      Participant

      Hi,

      In my application I make use of composite objects in combination with the ORM for instance a TPerson having a TAddress property. Which I will use like this:

      Person := ORM.Query<TPerson>([1]);

      Person.Address := ORM.Query<TAddress>([1]);

       

      • Is it correct that I should not create the TAddress in the Create constructor because it will give a memory leak when used as in the above example? If yes, is it wise/practical to have another constructor for instance CreateWithComposites that does create the composite objects?
      • When you use ORM.QueryList does that create the ObjectList as well or does it just fills it? I thought it create the list as well but in the ORM standalone demo I saw that in the TPerson2 constructor the FAccounts composite object was created. I am a little confused.

      Thanks in advance!

    • #54186
      kimbomadsen
      Keymaster

      Say:
      TPerson = class

      FAddress:TAddress;
      end;

      A person could exist without an address, why Address having the value of nil is a valid situation. Hence you should generally not instantiate an Address instance unless you absolutely know a Person have an address.

      So you assumption is correct.

      Im not sure CreateWithComposites would be a good idea, because how will it know exactly which composites to instantiate with an empty, but instantiated value, and which not to. Further having an instantiated but empty address does also “logically” make sense. Either you have an address or at least a tentative address (because you are about to fill it out) or you dont. In the later case, Address ought to be nil.

      QueryList returns a TObjectList<TYourclass>.

      kbmMW however checks if it needs to instantiate a new list or if a list already exists. In the later case, it will reuse that one.

    • #54187
      kimbomadsen
      Keymaster

      Typo:

      Further having an instantiated but empty address does also “logically” not make sense.

Viewing 2 reply threads
  • You must be logged in to reply to this topic.