List Disposal

Wagner,


I the following:

procedure TNaharTasks.ProcessTasks;
var
  Tasks: TList<TEntityTask>;
  Task: TEntityTask;
begin
  Tasks := Model.DataView['tasks.active.list'].AsList as TList<TEntityTask>;
  try
    for Task in Tasks do
      if Now > Task.Start then
        Start(Task)
  finally
    Tasks.Free;
  end;
end;

where Model.DataView is this:
      result.AsList := OManager.Find<TEntityTask>.Where(TLinq.Eq('active', true) and not TLinq.Eq('running', true)).AddOrder(TOrder.Asc('start')).List;

The is list is generated according the query.

The problem is that Tasks.Free raises an "Invalid pointer operation", and looks loke it makes my object get released (handled by an refcount interface).

That is strange for me. If I remove that Tasks.Free it works. that is not going to be a memory leak?



That code looks correct. So it must be something else in your code not listed here. Tasks.Free should be called because it's a regular TList<T> and Aurelius does not destroy.

Maybe you are destroying it in  your "result" variable (not sure what type it is and/or if it managed the object in AsList proeprty?).