Access Violation loading List

Hi,

I got some troubles using aurelius, in particular with XData. I have a form with a AureliusDataSet where I set a Source List that I get from server. After that, if I double click a record on my dbgrid, it opens a form with the detail about it and I can close or change information. If I save new information, when I try to reload the list on the ListForm, I usually get an external exception and Aurelius Engine stops working: every operation I try to execute report me an Access Violation and I have to close my application. The same thing appens if i only close the detail form and open another one several times (like 10). I taught it was a xdata issue, so i tried also on a local database without xdata, but i got the same problem. 

Here's the procedures where I get stucked:

//after throwing this procedure, Aurelius Engine gets blocked
procedure TProdottiPrinterLoadListPresenter.LoadPrinter(Sender: TObject);
var
  LfrmProdottiLoadPrinter: TfrmProdottiPrinterLoad; //the detail form
  LRestClient: TMP_RestClient;  //class that contains procedure to call services from server
begin
  LfrmProdottiLoadPrinter:= TfrmProdottiPrinterLoad.create(True);
  try
    LfrmProdottiLoadPrinter.ShowModal;
  finally
    LfrmProdottiLoadPrinter.free;
  end;

  LRestClient:= TMP_RestClient.create(rmGet);
  try
    //the aureliusdataset I use on my view
    FfrmProdottiPrinterLoadList.getAureliusDataset('dstPS').Close;
    FfrmProdottiPrinterLoadList.getAureliusDataset('dstPRINTERLOAD').Close;

    LRestClient.ReturnedInstancesOwnership:= False;

    if assigned(FPRINTERLOADList) then
    begin
      try
//I free my List and clear every object stored in it
        FPRINTERLOADList.clearLista;
        FPRINTERLOADList.Free;
      except
        FPRINTERLOADList:= nil;
      end;
    end;
    //I call a service from DB to filter my data
    FPRINTERLOADList:= TClearableList<TMP_PRODUCTLOAD>(
       LrestClient.getPRODUCTLOADbyCATEGORY(1));

    FfrmProdottiPrinterLoadList.setAureliusDatasetSource(FPRINTERLOADList,
       'dstPRINTERLOAD');
    FfrmProdottiPrinterLoadList.getAureliusDataset('dstPS').Open;

  finally
    LRestClient.Free;
  end;
end;

//if I call the constructor several times during my application (maybe i close the form and I reopen it)
//I get the same situation
constructor TProdottiPrinterLoadListPresenter.create(
  AfrmProdottiPrinterLoadList: IfrmProdottiPrinterLoadList;
  AID_MASTER_DATA: integer);
var
  LRestClient: TMP_RestClient;
begin
  FfrmProdottiPrinterLoadList:= AfrmProdottiPrinterLoadList;
  LRestClient:= TMP_RestClient.create(rmGet);
  try
    LRestClient.ReturnedInstancesOwnership:= False;
    FPSList:= TClearableList<TMP_PS>(LRestClient.getPSbyPRODUCT_CATEGORY(1));
    FPRINTERLOADList:= TClearableList<TMP_PRODUCTLOAD>(
       LRestClient.getPRODUCTLOADbyCATEGORY(1));
  finally
    LRestClient.Free;
  end;
end;

function TMP_RestClient.getPRODUCTLOADbyCATEGORY(
  AID_CATEGORY: integer): TList<TMP_PRODUCTLOAD>;
var
  LServices: IGetterServices;
begin
  LServices:= XDataClient.Service<IGetterServices>;
  result:= LServices.getPRODUCTLOADbyCATEGORY(
     AID_CATEGORY);
end;

//My Service implemented on server
function TGetterServices.getPRODUCTLOADbyCATEGORY(
  AID_CATEGORY: integer): TList<TMP_PRODUCTLOAD>;
begin
  result:= TXDataOperationContext.Current.GetManager.
           CreateCriteria<TMP_PRODUCTLOAD>.
           CreateAlias('MP','mp').
           CreateAlias('mp.PC','pc').
           Add(TExpression.Eq('pc.ID_PC',AID_CATEGORY)).
           Add(TExpression.Eq('ISASSIGNED',false)).
           AddOrder(TOrder.Asc('YEAR')).
           AddOrder(TOrder.Asc('NUMBER')).
           List;
end;

In this case I use a service, but I also tried using TXDataClient.List<T>

I can't understand if there is some issue in my code (but it's strange that it appens not only with this procedure, but also when I open several times my ListForm and close it destroying everything) or something in Aurelius Engine.

So far I couldn't identify any issue in code, but looks like a typical memory management problem (you are accessing something that you previously destroyed). 

Please provide the full call stack at the moment the error happens, it helps finding out the problem.

It seems that using my TMP_RestClient as TProdottiLoadListPresenter Field instead of a local Var and let XDataClient destroy my object I resolved my problems. Thank you