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

Adding and Deleting Object Crashes Autocad

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
743 Views, 7 Replies

Adding and Deleting Object Crashes Autocad

Hi,

 

Anyone knows how to improve the memory allocation of autocad.net application. I often get autocad crashes in the application and most of the cause is how autocad handles the memory. i am not sure if it is application related or if there is a way to configure the application to have stable memory allocation.

 

Everytime I do add autocad objects and delete autocad objects programmatically the memory always sky rocket and I am very very very frustrated.I would really appreciate any tips or help to improve the performance.

 

Thanks and regards

7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

Please note that I am using intel corei5 2.5Ghz and 4G of memory. I dont think adding more memory is the solutions. I really do think it has something to do with configuring this autocad application in .net. I just dont know how to do it.

Message 3 of 8
Anonymous
in reply to: Anonymous

once you have added an object or deleted it, did you use Transction.Commit() and then Dispose the transcation(by using Transction.Dispose())? could you post some snippet of your code that crush autocad?

Message 4 of 8
Anonymous
in reply to: Anonymous

here a sample coding I normally do

.

.

.

Using lock As DocumentLock = doc.LockDocument
 Dim trans As Transaction = db.TransactionManager.StartTransaction()
 Try
                 Using trans

.

.

.
                     Dim bt As BlockTable =
 trans.GetObject(db.BlockTableId,
 Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
                     Dim modelSpace As BlockTableRecord =
 trans.GetObject(bt(BlockTableRecord.ModelSpace),
 Autodesk.AutoCAD.DatabaseServices.OpenMode.ForWrite)
                     modelSpace.AppendEntity(br)
                     trans.AddNewlyCreatedDBObject(br, True)
                     trans.Commit()
                 End Using
             Catch ex As Exception
                 trans.Dispose()
             Finally
                 trans.Dispose()
             End Try
 End Using

Message 5 of 8
norman.yuan
in reply to: Anonymous

It is very likely that you was led to think it was AutoCAD memory management issue when your code crashes AutoCAD, causing fatal error message, which mentions something about accessing memory error.

 

4G memory in computer may not be good enough for AutoCAD runs smoothly, but it should runs OK, and disk space would be used if more memory i sneeded (to make computer even slower). But your case of crash is very possibly caused by your code that does not handle exception good enough.

 

The code you just showed seems OK, as long as in the call:

 

AppendEntity(br), where br is an Entity (BlockReference?).

 

Have you stepping through the code in debugging mode to identify which line of code causes the crash?

Norman Yuan

Drive CAD With Code

EESignature

Message 6 of 8
Anonymous
in reply to: Anonymous

OK, amigo, i rarely use VB.NET to code, just have some experience in VB 6.0.

as your code shows, can you explain the variable 'br' means? in some languages like c#, we should declare a variable before we use it, whereas in VB, you can use it immediately, so here your 'br' has no type(variant type, if you insist it has one), unlike other strong type languages, this may cause type cast at runtime, so here your code may need more time and resources to try to execute, but, but your 'br' is null here, so your code may crash.

how about:

Dim br as Line...

and write some code.

finally, i usually handle the exception like this(C# style):

try

{

...

}

catch

{

    trans.abort();

    throw;

}

finally

{

    trans.dispose();

}

 

hope this may be helpful to you.

Message 7 of 8
Anonymous
in reply to: Anonymous

Hi cdinten,

 

Thanks for the sample snippet. I am currently recoding because from what I read from blogs and autodesk comment normally when you use using keyword on transaction it normally automatically dispose the transaction. I am trying to put all objects like polyline, dbobject, entity etc. inside using keyword and hope it will help improve the performance and put an end to crashes. I'll keep you posted after I'm done with recoding the program.

 

Got the idea from this link: http://through-the-interface.typepad.com/through_the_interface/2010/03/the-stephen-and-fenton-show-a....

 

Regards,

Message 8 of 8
Anonymous
in reply to: Anonymous

by the way

 br is my variable for BlockReference

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