Analytica Decision Engine Reference/Releasing ADE Objects in .NET


4.6  •  5.0  •  5.1  •  5.2  •  5.3  •  5.4  •  6.0  •  6.1  •  6.2  •  6.3  •  6.4  •  6.5

When using ADE (or any COM-server) from a .NET application, it is important to explicit release those objects in your code. The need to do this is a result of the way that garbage collection works in .NET.

If you have used ADE from VB6 -- prior to VB.NET -- this need to explicitly release objects didn't exist. As soon as the last reference to the object disappeared, the object was automatically released and reclaimed. However, the actual release doesn't occur when you have finished with the object - it happen when garbage collection runs. This delay can result in problems, and hence, the need to explicitly release objects.

The following illustrates how to release an object:

CAEngine ade = new CAEngineClass;
ade = Nothing

Prior to .NET, the call to ReleaseComObject was unnecessary.

You must release all ADE objects in this way: CAObject, CATable, CAIndex, and CARenderingStyle.

What happens if you don't call ReleaseComObject?

In this event, the release doesn't occur immediately. An Interop wrapper object sits around in the managed heap until the next garbage collection runs. This Interop object maintains a pointer to the actual COM object, so the COM object hangs around until garbage collection runs.

If you are using the out-of-process server, ADE6.CAEngine, which is the more commonly used and recommended for web applications, then ADE runs in a separate process, and hence separate memory space, from the rest of your application. A low-memory condition in your own process may trigger a garbage collection, but if you aren't releasing objects, your own application may have plenty of memory while unused objects are collecting in the ADE process. Thus, if your application runs for a long time, your ADE process's memory space may eventually fill up.

Worse consequences can occur if you delete indexes used by your CATable objects. The CATable object, waiting for garbage collection to be deleted, may use an Analytica index. If you delete that index in your code, the zombie CATable doesn't know that. Later, when it gets collected, it tries to release the index that doesn't exist any more, and bad things can happen. Usually a delayed crash -- so that the location of the crash is unrelated to the actual source of the crash. These are hard to debug.


An alternative to calling ReleaseComObject every time you release an object is to call

System.GC.Collect( )

For example:

 CAEngine ade = new CAEngineClass;
 CAObject obj = ade.Get("Va1");
 CATable tab = obj.ResultTable;
 CAIndex ind = tab.GetIndexObject("In1");
 ind = null;
 tab = null;
 obj = null;
 ade = null;

You are not allowed to post comments.