While programming with Civil 3D COM objects, it is very common create AeccXxxx variables as class variables (modifiers shared in VB.NET or static in C#), like in the code below. This makes like easier, but leaves the Aecc reference longer than required, which can result in problems.
One way to improve that is call ReleaseComObject for each variable declared with this modifier. This is not required for variables declared inside methods, which are automatically disposed when the method ends. Also, as the AcadApplication is the host, there is no need to manually release it either.
Private Shared _acadApp As AcadApplication
Private Shared _aeccApp As AeccApplication
Private Sub GetCivilObjects()
' get Acad App
_acadApp = Application.AcadApplication
' get Aecc App
_aeccApp = _acadApp.GetInterfaceObject( _
"AeccXUiLand.AeccApplication.10.0")
End Sub
' in the end (before exit)
Private Sub ReleaseCivilObjects()
' then release/dispose Aecc App
System.Runtime.InteropServices.Marshal.ReleaseComObject(_aeccApp)
_aeccApp = Nothing
' call garbage collector (suggested only once at the end)
System.GC.WaitForPendingFinalizers()
System.GC.Collect()
End Sub
Public Sub MyRoutine()
GetCivilObjects()
'use aeccApp the variable
'...
'...
ReleaseCivilObjects()
End Sub