Hi,
A performance issue of my application lead me here, after dbConnect.GetLinks run 1000 times, AutoCAD take about 9 to 11 MB more memory (from 104,000 to 113,000).
I go back to test my old VBA version, got the same problem
Is there a memory leak in dbConnect.GetLinks ?
My function which use dbConnect.GetLinks will run much slower in 2nd time than in first time. I think it could be the reason.
How to release the COM in .NET completely? I simple set the object as null. Is this good enought?
here is code
[code]
public static ArrayList GetKeyValue( ObjectId objId, string LinkTemplateName )
{
if ( LinkTemplateName == null || LinkTemplateName.Length == 0 )
throw new ArgumentNullException ( "CAOLIB.GetKeyValue.LinkTemplateName" );
if ( objId.IsNull )
throw new ArgumentNullException ( "CAOLIB.GetKeyValue.objId" );
//
CAO.DbConnect dbConnectCOM;
Autodesk.AutoCAD.Interop.AcadApplication acadCOMApp;
Autodesk.AutoCAD.Interop.AcadDocument acadCOMDoc;
acadCOMApp = (Autodesk.AutoCAD.Interop.AcadApplication) AcadApp.AcadApplication;
acadCOMDoc = acadCOMApp.ActiveDocument;
CAO.LinkTemplates myLinkTemplates;
CAO.LinkTemplate myLinkTemplate;
CAO.Links Links;
ArrayList colRet = new ArrayList();
try
{
if ( acadCOMApp != null )
{
// get link templates
// for AutoCAD 2004/2005/2006
dbConnectCOM = (CAO.DbConnect) acadCOMApp.GetInterfaceObject( "CAO.DbConnect.16" );
myLinkTemplates = dbConnectCOM.GetLinkTemplates( acadCOMDoc );
// get link from name
myLinkTemplate = null;
try
{
myLinkTemplate = myLinkTemplates.Item( LinkTemplateName );
}
catch (System.Exception caught)
{
return null;
}
Int32[] ObjIds = new Int32[1];
ObjIds[0] = objId.OldId;
Object oIDs = ObjIds;
//
Object ObjMissing = Type.Missing;
// get link from ObjId and link template
// CAO.LinkType.kEntityLinkType 2
Links = dbConnectCOM.GetLinks( myLinkTemplate, oIDs, 2, acadCOMDoc );
foreach ( CAO.Link link in Links )
{
if ( objId.OldId == link.ObjectID )
{
// get link value
string strRet = link.KeyValues.Item(0).Value.ToString();
colRet.Add(strRet);
}
}
}
}
catch (System.Exception caught)
{
colRet = null;
// throw ?
}
finally
{
// clean
myLinkTemplates = null;
Links = null;
myLinkTemplate = null;
dbConnectCOM = null;
acadCOMDoc = null;
acadCOMApp = null;
}
return colRet;
}
[/code]
Thank you,
Wes
Windwos 2003 Server, AutoCAD 2006, .Net 1.1, Visual Studio 2003, Pentium 4 3.20GHz, 1.5 GB RAM
Windows 10 64 bit, AutoCAD (ACA, Map) 2023