2261279 - DI API:How To Handle Memory Leak In COM Objects
When using Data Interface API (DI API) COM objects, you find memory is not released and API actions are slow.
System behavior/ Functionality description/ Business process
For the best performance and memory handling consider below recommendation.
- Use one Company connection per database schema and avoid repeated connections.
- In general, it should be sufficient to initialize the object once and release the object at the end of a loop.
- Declare & instantiate COM objects at the last moment possible.
- ReleaseComObject(obj) or FinalReleaseComObject(obj) for ALL objects, at the soonest moment possible.
- Always ReleaseComObject(obj) or FinalReleaseComObject(obj) in the opposite order of creation.
- NEVER call GC.Collect() except when required for debugging.
- If you are planning to create a program which will be running for several hours continuously, or creating 1000's of documents with multiple child objects, then explicit memory release should be considered.
- If you running a DI API program as a windows service, it is recommended to schedule a restart at least once a day.
Example with respect to DI API, adding Sales Order