Should we free the ManyValueAssocation list in the entity's destructor?

I am somewhat uncertain - for ManyValueAssocation list, whose responsibility to free it? In the example of the following code, FUserRole: TList<TUserRole>, should we free it in the entity's destructor?

  [Entity, Automapping]
  [Aurelius.Mapping.Attributes.Model(SecurityModel)]
  [Table('USERS')]
  [UniqueKey('USER_NAME')]
  TUser = class
  private
    FId: Integer;
    FUserName: string;
    FPassword: string;

    [ManyValuedAssociation([], CascadeTypeAllRemoveOrphan, 'FUser')]
    [ForeignJoinColumn('USER_ID', [TColumnProp.Required])]
    FUserRoles: TList<TUserRole>;  // Question: Do we need to free this list in destructor?

    FCreateOn: TDateTime;
    FDescription: Nullable<string>;
  public
    constructor Create;
    destructor Destroy; override;
    property Id: Integer read FId write FId;
    property UserName: string read FUserName write FUserName;
    property Password: string read FPassword write FPassword;
    property UserRoles: TList<TUserRole> read FUserRoles write FUserRoles;
    property CreateOn: TDateTime read FCreateOn;
    property Description: Nullable<string> read FDescription write FDescription;
  end;

The entity class is responsible to create and free the list. The objects in the list, however, are destroyed by the manager. Thus, create a regular TList and just destroy it.

In this documentation topic you have an example of how to declare classes with lists:
http://www.tmssoftware.biz/business/aurelius/doc/web/lazy-loading_associations.html.

It's recommended to always declare lists as lazy-loading, as there is virtual no benefit in not doing so.

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