DI API Memory Leak in SAP Business One 9.0

DI API as we know is an important component in SAP Business One which allows other third party applications to interact with the ERP system. It allows to push and receive data to/from SAP Business One. Though new integration components are available like DI Server which allows the data to be synced in batch provides greater performance, still DI API is widely used in many solutions offered by SAP Partner. One of the biggest reason of using this is no additional license requirement, while DI Server License comes up at an additional cost of few hundred euros.

But in current release of SAP Business One 9.0, it is reported by several SAP Partners and consultants that DI API faces a fatal bug of Memory Leak while exchanging the data. Let’s have a detail look of incidents reported in several forums regarding the DI API Memory Leak in SAP Business One 9.0.


With each API calls DI API exceeding the usage of RAM even when running the same process, eventually reaching the threshold point of getting free RAM and crashing the subsequent process which accessing the DI API. So in this way the worker process finally hang the application and crashes it.

Example 1:

Reported in SCN, below Sales Order creation process before running has an available free RAM of 6GB. This is a dummy Sales Order Creation Process in SAP Business One through DI API:

  1. //————————-
  2. // Declaring SAP objects…
  3. //————————-
  4. SAPbobsCOM.Company CurrentCompany = null;
  5. SAPbobsCOM.Documents Order = null;
  6. SAPbobsCOM.BusinessPartners bp = null;
  7. SAPbobsCOM.Items Items = null;
  8. SAPbobsCOM.AdditionalExpenses Expenses = null;
  9. //————————-
  10. // Opening a company object
  11. //————————-
  12. SAPbobsCOM.Company CurrentCompany = GetSAPCompany(SessionID);
  13. if (CurrentCompany != null)
  14. {
  15.    Order = (SAPbobsCOM.Documents)CurrentCompany.GetBusinessObject(BoObjectTypes.oOrders);
  16.     bp = (SAPbobsCOM.BusinessPartners)CurrentCompany.GetBusinessObject(BoObjectTypes.oBusinessPartners);
  17.     Items = (SAPbobsCOM.Items)CurrentCompany.GetBusinessObject(BoObjectTypes.oItems);
  18.     Expenses = (SAPbobsCOM.AdditionalExpenses)CurrentCompany.GetBusinessObject(BoObjectTypes.oAdditionalExpenses);
  19. }
  20. //————————————————–
  21. // Here would be the code to create a Sales Order…
  22. //————————————————–
  23. //————————
  24. // Releasing everything…
  25. //————————
  26. if (Order != null)
  27. {
  28.     System.Runtime.InteropServices.Marshal.ReleaseComObject(Order);
  29.     Order = null;
  30. }
  31. if (bp != null)
  32. {
  33.     System.Runtime.InteropServices.Marshal.ReleaseComObject(bp);
  34.     bp = null;
  35. }
  36. if (Items != null)
  37. {
  38.     System.Runtime.InteropServices.Marshal.ReleaseComObject(Items);
  39.     Items = null;
  40. }
  41. if (Expenses != null)
  42. {
  43.     System.Runtime.InteropServices.Marshal.ReleaseComObject(Expenses);
  44.     Expenses = null;
  45. }
  46. if (CurrentCompany != null)
  47. {
  48.     if(CurrentCompany.Connected)
  49.         CurrentCompany.Disconnect();
  50.     System.Runtime.InteropServices.Marshal.ReleaseComObject(CurrentCompany);
  51.     CurrentCompany = null;
  52. }

Initially memory taken was 40 MB, releasing 36 MB after each time execution and 4 MB of memory usage is growing with each Sales Order creation. Eventually in some system integration such as eCommerce where there is a need to push thousands of Sales Order per hour, this process will shorten the Free RAM in no time and hangs or crashes the application like below

application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7afa2

Faulting module
name: B1_DIInternalFields90Ace.dll, version:, time stamp: 0x51799cf5

Exception code:

Fault offset:

Faulting process
id: 0x1a74

application start time: 0x01ceb48157da7b5d

application path: c:\windows\system32\inetsrv\w3wp.exe

Faulting module
path: C:\Program Files\SAP\SAP Business One DI API\DI API

Report Id:


It is mostly advised by other consultants not to use DI API until there is some updated patch level released with this fix, still below solutions are mentioned. You can take a look and try if this helps:

Garbage Collector

Force the system garbage collector




Alternative Method

.Net franmework won’t let you unload any loaded assembly and DI-proxy is only an assembly. The solution is using alternative method like:

  • Going at a minimum to DI-Server – B1WS which consumes less memory, but for which you can force the unload of the service and by doing so to force it to release all its memory,
  • Going ideally to B1if, which with its own DI-proxy mechanism will be able to restart periodically,

If can’t change from API, move all the business logic in a separate process (exe, not web-service neither DLL) which will be called by your web page and removed from memory when its job is ended.

Also Read:

All details about SAP B1 DI API, DI Server and B1WS