Analytica Decision Engine Reference/Release ADE Objects BEFORE deleting Analytica objects
Important programming Note
When using ADE, it is critical that your code releases any ADE objects before Analytica objects used by your code are deleted. Failure to do so can result in a crash, and often the crash occurs much later so that it is hard to associate the crash with the original source of the problem.
Analytica objects may be deleted by
- Closing your model, CAEngine::CloseModel
- Deleting the object, via CAEngine::DeleteObject
- Deleting a module object that contains the object, via CAEngine::Delete
- Using a typescript command, such as delete, to delete the object.
It is fairly obviously which object CAObject, CAIndex instances point to. These should be released BEFORE deleting the underlying object. CATables also point to an underlying object, the result or definition object, but also to index objects. If you delete any index object that belongs to the table, you need to release the CATable instance first!!
The following code demonstrates (non-.NET):
Good code:
CAObject obj = ade.Get("Va1") ... obj = Nothing ade.DeleteObject("Va1") obj = ade.Get("Va2") ...
Bad code:
CAObject obj = ade.Get("Va1") ... ade.DeleteObject("Va1") obj = ade.Get("Va2") ...
Good .NET code:
CAObject obj = ade.Get("Va1") ... System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) ' In .NET, you must explicitly release obj = Nothing ade.DeleteObject("Va1") obj = ade.Get("Va2") ...
Enable comment auto-refresher