cancel
Showing results for 
Search instead for 
Did you mean: 

SB1 2007A DI Memory leak?

Former Member
0 Kudos

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;

}

}

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Answers (1)

Answers (1)

former_member201110
Active Contributor
0 Kudos

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