.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CAO dbConnect.GetLinks memory leak?

3 REPLIES 3
Reply
Message 1 of 4
wesbird
885 Views, 3 Replies

CAO dbConnect.GetLinks memory leak?

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
3 REPLIES 3
Message 2 of 4
Anonymous
in reply to: wesbird

You should call Marshal.ReleaseComObject() on
every COM object.

You can also call Marshal.FinalReleaseComObject()
to force the object to be destroyed.

But if that's happening in VBA, then the problem
may not be that the COM object's aren't being
released, because VBA does that for you.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting AutoCAD 2000 through 2008
http://www.acadxtabs.com

wrote in message news:5718751@discussion.autodesk.com...
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
Message 3 of 4
facilicad
in reply to: wesbird

We have been havine issues in our VBA application related to DbConnect.  At least we think that is where the issue lies.  We use the cammand GetLinks all over the place.  When we first initiate the application, there does not seem to be any issues.  After a series of commands that use GetLinks, we start having issues with lost links and mutiple links.  I saw this thread, but it is from 2007 and does not shed any light on VBA applications.  It seems the solution is directly related to .net.  Is there anything you can tell us with this issue and VBA?

Message 4 of 4
wesbird
in reply to: facilicad

I already migrated all my VBA code to .Net. It basic works, still problem here and there. Now I have experised GetLink miss link value.   and the big problem is, I cannot consist repeat the problem which make it very hard to debug.

 

I am current in AutoCAD 2010, .Net 3.5, Visual Studio 2008. 

Windows 10 64 bit, AutoCAD (ACA, Map) 2023

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost