LineLst.RemoveAt(0);
method 2;Line fristLine = LineLst.First();
LineLst.Remove(firstLine);
firstLine.Dispose();
... //Other code
Line myLine = new Line(ptStart,ptEnd);
LineLst.Add(myLine);
... //more other code
/*I have define lots of Lines in this way,and add all of them to the LineLst.
But I didn't add them to any Database.
Now I want to remove the lines from the list one by one until the LineLst is empty.
So,I should dispose them.*/
while(LineLst.Count() > 0)
{
Line fristLine = LineLst.First(); //Obtain the first line.
LineLst.Remove(firstLine); //Remove it form the List, so the loop can stop when the List is empty
...//Some other useful code
//At the end,the loop line need to be disposed
firstLine.Dispose();
}
I didn't add them to a Database.So, is my way right?LineLst.First().Dispose();
Point3d myPoint = new Point3d(0,0,0);
It's good practice to dispose any database objects you create or open via the using statement and not wait for the garbage collector to do it for you.
Everything but the singletons like the database itself of course.
On when to dispose - sorry Draftek, I slightly disagree. If you open a DBObject in a transaction, then calling Dispose is not necessary, because AutoCAD has ownership of the object and takes care of it for you. Although - as I said before - calling Dispose on those DBObjects won't hurt (it just makes your code slightly harder to read).
Stephen started his career as a scientist, and has a PhD in atomic and laser physics from the University of Oxford.
Stephen, it was Gopinath Taget in his class on current .NET design patterns.
Stephen, it was Gopinath Taget in his class on current .NET design patterns.
Where were you sitting?