Conserving Memory in Bold

How to minimize memory usage in Bold.

In doing a report on some Bold object your code might be something like this:



var

  EmpList:TEmployeeList;

  i : integer;

  Emp:TEmployee;

  j : integer;

begin

  EmpList := TBoldSystem.DefaultSystem.ClassByExpressionName['Employee'] as TEmployeeList;

  For i := 0 to EmpList.Count - 1 do

  begin

    Emp := EmpList[i];

    // Processing Here

  end;

end;



A side effect of this is that after this is run all employee Business Objects (BO) will be loaded in memory. This is fine for a small number of employee however if you have thousand/millions of BOs you might find yourself running out of memory. To get arround this problem you can Unload the BO from memory after you are done processing.



var

  EmpList:TEmployeeList;

  i : integer;

  Emp:TEmployee;

  j : integer;

begin

  EmpList := TBoldSystem.DefaultSystem.ClassByExpressionName['Employee'] as TEmployeeList;

  For i := 0 to EmpList.Count - 1 do

  begin

    Emp := EmpList[i];

    // Processing Here

    EmpList.Locators[i].UnloadBoldObject;

  end;

end;





Note: If you change the BO, you must save (or discard the changes) it to the database before unloading or you will receive an exception.

 

Share this article!

Follow us!

Find more helpful articles: