on 04-05-2009 9:08 PM
Hi,
I've got a DI application containing the code fragment below. It contains a loop that loads an item, then loops through the price lists and updates a specific pricelist.
It seems that every time the loop runs about 1MB of is added to the SAP Business One process. If the loop runs long enough, SAP B1 runs out of memory.
Is there anyway to perform a large number of DI operations in a loop without the memory leak?
Cheers,
Ben
Items ITM = (Items)B1Connections.diCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);
Items_Prices Prices = null;
for (int i = 0; i < gvPriceList.DataRowCount; i++)
{
try
{
B1Data.dtItemPricesRow row = (B1Data.dtItemPricesRow)gvPriceList.GetDataRow(i);
ITM.GetByKey(row.ItemCode);
Prices = ITM.PriceList;
for (int j = 0; j < Prices.Count ; j++)
{
Prices.SetCurrentLine(j);
if (Prices.PriceList == int.Parse(PriceList_Purch))
{
try
{
Prices.Currency = row.Currency;
}
catch
{
}
Prices.Price = (double)row.NettPurchasePriceForeign;
ITM.Update();
break;
}
}
}
Hi Ben,
This is a pretty big memory leak using this object.
What patch of Business One are you using? There was an issue fixed in 2007A PL37 (Note 1151766).
I would recommend logging a message for SAP support to report this leak.
Cheers,
Lisa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ben,
Unfortunately, the DI API is rather leaky and I've never found a 100% reliable method to stop leaks. You can improve the situation by calling garbage collection directly in your code.
Try this:
for (int i = 0; i < gvPriceList.DataRowCount; i++)
{
Items ITM = (Items)B1Connections.diCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);
Items_Prices Prices = null;
try
{
B1Data.dtItemPricesRow row = (B1Data.dtItemPricesRow)gvPriceList.GetDataRow(i);
ITM.GetByKey(row.ItemCode);
Prices = ITM.PriceList;
for (int j = 0; j < Prices.Count ; j++)
{
Prices.SetCurrentLine(j);
if (Prices.PriceList == int.Parse(PriceList_Purch))
{
try
{
Prices.Currency = row.Currency;
}
catch
{
}
Prices.Price = (double)row.NettPurchasePriceForeign;
ITM.Update();
break;
}
}
}
finally
{
// Clean up
System.Runtime.InteropServices.Marshal.ReleaseComObject(ITM);
ITM = null;
GC.Collect();
}
}
Kind Regards,
Owen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
110 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.