.NET

Reply
Distinguished Contributor
wesbird
Posts: 359
Registered: ‎12-05-2003
Message 1 of 4 (485 Views)

CAO dbConnect.GetLinks memory leak?

485 Views, 3 Replies
09-12-2007 10:44 AM
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
Vault Pro 2014, Windows 7 64 bit, AutoCAD (ACA, Map) 2014
*Tony Tanzillo
Message 2 of 4 (485 Views)

Re: CAO dbConnect.GetLinks memory leak?

09-13-2007 05:30 AM 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
Member
facilicad
Posts: 3
Registered: ‎03-12-2009
Message 3 of 4 (361 Views)

Re: CAO dbConnect.GetLinks memory leak?

05-11-2011 05:39 AM 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?

Distinguished Contributor
wesbird
Posts: 359
Registered: ‎12-05-2003
Message 4 of 4 (352 Views)

Re: CAO dbConnect.GetLinks memory leak?

05-11-2011 07:58 AM 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. 

Vault Pro 2014, Windows 7 64 bit, AutoCAD (ACA, Map) 2014
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.