Is this a memory leak or is freeing an object more manual

This is one of the classes generated by ModelMaker

  [Id('FpaymentTypeId', TIdGenerator.IdentityOrSequence)]
  TPaymentType = class
    [Column('paymentTypeId', [TColumnProp.Required, TColumnProp.NoInsert, TColumnProp.NoUpdate])]
    FpaymentTypeId: Integer;
    [Column('depositAmount', [], 50)]
    FdepositAmount: Nullable<string>;
    [Association([], CascadeTypeAll - [TCascadeType.Remove])]
    [JoinColumn('accountInfo', [], 'bankAccountTypeId')]
    FaccountInfo: TBankAccountType;
    [Column('version', [])]
    Fversion: integer;
    property paymentTypeId: Integer read FpaymentTypeId write FpaymentTypeId;
    property depositAmount: Nullable<string> read FdepositAmount write FdepositAmount;
    property accountInfo: TBankAccountType read FaccountInfo write FaccountInfo;
    property version: integer read Fversion write Fversion;

accountInfo is a property that I need to create an instance of the class if I want to assign data to it, but theres no destructor to free it if it exists when I dispose of the TPaymentType class.

Do these need to be destroyed manually eg

var o: TPaymentType;
o := GetSomePaymentTypeClass;
if assigned(o.accountInfo) then

or is there an option to generate code to free these in a destructor for me ? I've looked for an option but couldn't find one. Some of my classes contain deep hierarchies and could be difficult to free manually. The only other alternative I could see would be to code a procedure that takes the object and uses RTTI to traverse the properties and free any that needed freeing.

You should destroy it yourself like you are doing.
When using entities in Aurelius object manager, it's up to the manager to destroy the entities, so the entity itself shouldn't destroy entities.

Thanks for that Wagner. I have coded a procedure that uses RTTI to destroy the objects I created and that seems to work well.

With regard to objects created by the manager, how does the manager know when to free them ? If I was to hold on to a returned class from the manager should I clone it immediately then just ignore the returned object for the manager to free.


The manager will destroy its objects when it is destroyed itself.
Yes, you should a) clone the object; or b) set the OwnsObjects property to False (thus no manager object will be destroyed; or c) keep the manager alive as long as you need the object (I prefer the latter).