<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I create a Line without calling Dispose? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589426#M10770</link>
    <description>&lt;P&gt;Just my opinion&lt;/P&gt;&lt;P&gt;It’s bad form because CreateLine is not only creating an entity, but also adding it to a transaction, then a database.&lt;/P&gt;&lt;P&gt;The caller gets a DB Object that’s closed and disposed&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Separating your functions out is clearer, CreateLine, GetColor, AddEntityToCurrentSpace.&lt;/P&gt;&lt;P&gt;CreateLine, should only create a line, in a new state, the caller should be responsible for what happens next&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don’t need a line, use a Geometry Object to do your calculations, maybe LineSegment3d&lt;/P&gt;&lt;P&gt;GetColor(seg a, segb)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;edit&lt;/P&gt;&lt;P&gt;returning an object ID is returning a known state. I know its a pain to open and close, but its defined behavior&lt;/P&gt;</description>
    <pubDate>Thu, 01 Dec 2022 00:17:50 GMT</pubDate>
    <dc:creator>daniel_cadext</dc:creator>
    <dc:date>2022-12-01T00:17:50Z</dc:date>
    <item>
      <title>How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11588891#M10767</link>
      <description>&lt;P&gt;I would like a CreateLine function that creates a line, adds it to the current transaction and space, and returns it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After the line is returned, I want to use it to do some calculation or to change some of its properties.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do I need to dispose it or not?&lt;/P&gt;&lt;P&gt;If I dispose it, I can't do anything with it later.&lt;/P&gt;&lt;P&gt;If I don't dispose it, memory leaks or other bad things will happen.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was thinking about a function like this one, used by the pseudocode that follows it:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;public static &lt;/SPAN&gt;&lt;SPAN&gt;Line &lt;/SPAN&gt;&lt;SPAN&gt;CreateLine&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Document &lt;/SPAN&gt;&lt;SPAN&gt;dwg, &lt;/SPAN&gt;&lt;SPAN&gt;Point3d &lt;/SPAN&gt;&lt;SPAN&gt;p1, &lt;/SPAN&gt;&lt;SPAN&gt;Point3d &lt;/SPAN&gt;&lt;SPAN&gt;p2&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;trans = &lt;/SPAN&gt;dwg&lt;SPAN&gt;.&lt;/SPAN&gt;Database&lt;SPAN&gt;.&lt;/SPAN&gt;TransactionManager&lt;SPAN&gt;.&lt;/SPAN&gt;TopTransaction&lt;SPAN&gt;;&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;space = (&lt;/SPAN&gt;&lt;SPAN&gt;BlockTableRecord&lt;/SPAN&gt;&lt;SPAN&gt;)trans.&lt;/SPAN&gt;&lt;SPAN&gt;GetObject&lt;/SPAN&gt;&lt;SPAN&gt;(dwg.&lt;/SPAN&gt;&lt;SPAN&gt;Database&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;CurrentSpaceId&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;OpenMode&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;ForRead&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;BR /&gt;&lt;/SPAN&gt;    &lt;SPAN&gt;using &lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;line = &lt;/SPAN&gt;&lt;SPAN&gt;new &lt;/SPAN&gt;&lt;SPAN&gt;Line&lt;/SPAN&gt;&lt;SPAN&gt;(p1, p2))&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;    {&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;        space.&lt;/SPAN&gt;&lt;SPAN&gt;AppendEntity&lt;/SPAN&gt;&lt;SPAN&gt;(line);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;        trans.&lt;/SPAN&gt;&lt;SPAN&gt;AddNewlyCreatedDBObject&lt;/SPAN&gt;&lt;SPAN&gt;(line, &lt;/SPAN&gt;&lt;SPAN&gt;true&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;return &lt;/SPAN&gt;&lt;SPAN&gt;line;&lt;BR /&gt;    }&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;BR /&gt;&lt;BR /&gt;l1 = CreateLine(dwg, p1, p2);&lt;BR /&gt;l2 = CreateLine(dwg, p3, p4);&lt;BR /&gt;if (l1.GetGeCurve().GetDistanceTo(l2.GetGeCurve()) &amp;lt; y) l2.Color = red;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;I think that this will not work because line is returned inside an using block, which means that it has been disposed by the time it is assigned to l1 or l2.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 19:37:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11588891#M10767</guid>
      <dc:creator>stefanome</dc:creator>
      <dc:date>2022-11-30T19:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589210#M10768</link>
      <description>&lt;P&gt;IMHO, that’s bad form.&lt;/P&gt;&lt;P&gt;Commit the transaction.&lt;/P&gt;&lt;P&gt;Return the line’s objectId from CreateLine,&lt;/P&gt;&lt;P&gt;re open both lines to do your comparing using openclosetransaction&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 21:52:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589210#M10768</guid>
      <dc:creator>daniel_cadext</dc:creator>
      <dc:date>2022-11-30T21:52:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589334#M10769</link>
      <description>&lt;P&gt;The point is that I want the CreateLine to return Line objects, because that's what I use to do my calculation. I don't do calculation with ObjectId objects.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If every time I call that function I get an ObjectId, then I need to use that ObjectId to get the Line object open for write, what's the point of returning an ObjectId?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps I should create one transaction per call, something like the code below. Creating one transaction per call seems to be highly inefficient, but it should work. I asked because I was wondering if there is a better way.&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;public static &lt;/SPAN&gt;&lt;SPAN&gt;Line &lt;/SPAN&gt;&lt;SPAN&gt;CreateLine&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Document &lt;/SPAN&gt;&lt;SPAN&gt;dwg, &lt;/SPAN&gt;&lt;SPAN&gt;Point3d &lt;/SPAN&gt;&lt;SPAN&gt;p1, &lt;/SPAN&gt;&lt;SPAN&gt;Point3d &lt;/SPAN&gt;&lt;SPAN&gt;p2&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;BR /&gt;    ObjectId id;&lt;BR /&gt;    using (var trans = dwg.TransactionManager.StartTransaction())&lt;BR /&gt;    {&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;space = (&lt;/SPAN&gt;&lt;SPAN&gt;BlockTableRecord&lt;/SPAN&gt;&lt;SPAN&gt;)trans.&lt;/SPAN&gt;&lt;SPAN&gt;GetObject&lt;/SPAN&gt;&lt;SPAN&gt;(dwg.&lt;/SPAN&gt;&lt;SPAN&gt;Database&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;CurrentSpaceId&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;OpenMode&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;ForWrite&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;using &lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;var &lt;/SPAN&gt;&lt;SPAN&gt;line = &lt;/SPAN&gt;&lt;SPAN&gt;new &lt;/SPAN&gt;&lt;SPAN&gt;Line&lt;/SPAN&gt;&lt;SPAN&gt;(p1, p2))&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;        {&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;            space.&lt;/SPAN&gt;&lt;SPAN&gt;AppendEntity&lt;/SPAN&gt;&lt;SPAN&gt;(line);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;            trans.&lt;/SPAN&gt;&lt;SPAN&gt;AddNewlyCreatedDBObject&lt;/SPAN&gt;&lt;SPAN&gt;(line, &lt;/SPAN&gt;&lt;SPAN&gt;true&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;BR /&gt;            id = line.ObjectId;&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;}&lt;BR /&gt;        trans.Commit();&lt;BR /&gt;    }&lt;BR /&gt;&lt;BR /&gt;    var topTrans = dwg.Database.TransactionManager.TopTransaction;&lt;BR /&gt;    return topTrans.GetObject(id, OpenMode.ForWrite);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Nov 2022 23:09:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589334#M10769</guid>
      <dc:creator>stefanome</dc:creator>
      <dc:date>2022-11-30T23:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589426#M10770</link>
      <description>&lt;P&gt;Just my opinion&lt;/P&gt;&lt;P&gt;It’s bad form because CreateLine is not only creating an entity, but also adding it to a transaction, then a database.&lt;/P&gt;&lt;P&gt;The caller gets a DB Object that’s closed and disposed&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Separating your functions out is clearer, CreateLine, GetColor, AddEntityToCurrentSpace.&lt;/P&gt;&lt;P&gt;CreateLine, should only create a line, in a new state, the caller should be responsible for what happens next&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you don’t need a line, use a Geometry Object to do your calculations, maybe LineSegment3d&lt;/P&gt;&lt;P&gt;GetColor(seg a, segb)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;edit&lt;/P&gt;&lt;P&gt;returning an object ID is returning a known state. I know its a pain to open and close, but its defined behavior&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 00:17:50 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589426#M10770</guid>
      <dc:creator>daniel_cadext</dc:creator>
      <dc:date>2022-12-01T00:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589457#M10771</link>
      <description>&lt;P&gt;You are saying this is wrong?&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;l1 = CreateLine(dwg, p1, p2);&lt;BR /&gt;l2 = CreateLine(dwg, p3, p4);&lt;BR /&gt;if (l1.GetGeCurve().GetDistanceTo(l2.GetGeCurve()) &amp;lt; y) l2.Color = red;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;and this is correct?&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;id1 = CreateLine(dwg, p1, p2);&lt;BR /&gt;l1 = trans.GetObject(id1, OpenMode.ForWrite);&lt;BR /&gt;id2 = CreateLine(dwg, p3, p4);&lt;BR /&gt;l2 = trans.GetObject(id2, OpenMode.ForWrite);&lt;BR /&gt;if (l1.GetGeCurve().GetDistanceTo(l2.GetGeCurve()) &amp;lt; y) l2.Color = red;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;When I see patterns of repeated lines (of code) like on the second snippet, I know it's time to refactor and create a function that does the job. id1 and id2 are only used to get l1 and l2. When I see that I think that it's bad, that's calling for a function that returns a Line, not an ObjectId.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the real world it's much worse: I have one function that creates the lines and passes them to another function that analyzes them and decides what to do with them. Some will not change, some will change color, some will be trimmed or extended, some will be split in two (the line will be shortened and one new one will be added), some will be deleted. Everything works around lines, and some lines already exist and some need to be created.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The function that analyzes the lines should only analyze the lines, shouldn't care about their status or the inner works of the database. The function knows that all the lines are open for write and it can change their properties. And if it needs to create new lines, for example when it's time to split a line, all it needs to do is call CreateLine again.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 00:31:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589457#M10771</guid>
      <dc:creator>stefanome</dc:creator>
      <dc:date>2022-12-01T00:31:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589503#M10772</link>
      <description>&lt;P&gt;I would say sample 2 is better than sample 1, some caveats, use an open close transaction, not the normal transaction,&lt;/P&gt;&lt;P&gt;It’s designed exactly for that purpose, Why does l1 need to be opened for write? Prefer upgradeOpen when the if succeeds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was suggesting something like&lt;/P&gt;&lt;P&gt;Line Createline(doc, pt1, pt2), set database defaults, points, default color etc, return the line, no usings, no transitions, no database, just return the line.&lt;/P&gt;&lt;P&gt;Do your calculations L2.Color = CalcColor(line a, line b)&lt;/P&gt;&lt;P&gt;Do something with the line, add it to the database or dispose it;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 00:59:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589503#M10772</guid>
      <dc:creator>daniel_cadext</dc:creator>
      <dc:date>2022-12-01T00:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589514#M10773</link>
      <description>&lt;P&gt;An even better approach would be&lt;/P&gt;&lt;P&gt;SegA CreateGeLineSeg(p1, p2)&lt;/P&gt;&lt;P&gt;SegB CreateGeLineSeg(p3, p4)&lt;/P&gt;&lt;P&gt;Color CalcColor(segA, SegB);&lt;/P&gt;&lt;P&gt;Objectid CreatelineFromSegAddAddIt(doc, color, seg)&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 01:08:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589514#M10773</guid>
      <dc:creator>daniel_cadext</dc:creator>
      <dc:date>2022-12-01T01:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589946#M10774</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/909070"&gt;@stefanome&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;I think that this will not work because line is returned inside an using block, which means that it has been disposed by the time it is assigned to l1 or l2.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So, why do you create the new Line with a using statement ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/909070"&gt;@stefanome&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;Do I need to dispose it or not?&lt;/P&gt;
&lt;P&gt;If I dispose it, I can't do anything with it later.&lt;/P&gt;
&lt;P&gt;If I don't dispose it, memory leaks or other bad things will happen.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You do not need to dispose it in the CreateLine function. While an entity (or any DBObject) is added to a Transactiion, it will be automatically disposed when the transaction is disposed.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 08:04:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11589946#M10774</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-12-01T08:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11590024#M10775</link>
      <description>&lt;P&gt;This will work:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        public static Line CreateLine(BlockTableRecord space, Point3d p1, Point3d p2)
        {
            var trans = space.Database.TransactionManager.TopTransaction;
            var line = new Line(p1, p2);
            space.AppendEntity(line);
            trans.AddNewlyCreatedDBObject(line, true);
            return line;
        }&lt;/LI-CODE&gt;
&lt;P&gt;With:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;            using (var tr = db.TransactionManager.StartTransaction())
            {
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                var l1 = CreateLine(curSpace, p1, p2);
                var l2 = CreateLine(curSpace, p3, p4);

                double y = 10.0;
                if (l1.GetGeCurve().GetDistanceTo(l2.GetGeCurve()) &amp;lt; y)
                    l2.ColorIndex = 1;
                tr.Commit();
            }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But simply doing this is simpler and clearer:&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;            using (var tr = db.TransactionManager.StartTransaction())
            {
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                var l1 = new Line(p1, p2);
                curSpace.AppendEntity(l1);
                tr.AddNewlyCreatedDBObject(l1, true);
                var l2 = new Line(p3, p4);
                curSpace.AppendEntity(l2);
                tr.AddNewlyCreatedDBObject(l2, true);

                double y = 10.0;
                if (l1.GetGeCurve().GetDistanceTo(l2.GetGeCurve()) &amp;lt; y)
                    l2.ColorIndex = 1;
                tr.Commit();
            }&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 01 Dec 2022 07:59:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11590024#M10775</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-12-01T07:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11590903#M10776</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/909070"&gt;@stefanome&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;&lt;P&gt;&lt;SPAN&gt;I think that this will not work because line is returned inside an using block, which means that it has been disposed by the time it is assigned to l1 or l2.&lt;/SPAN&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So, why do you create the new Line with a using statement ?&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Because I was doing what the documentation says I should do. My code follows &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-47E8A12E-2ED4-4E78-ADA3-AAC9B4223C3C" target="_blank" rel="noopener"&gt;this example&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;You do not need to dispose it in the CreateLine function. While an entity (or any DBObject) is added to a Transactiion, it will be automatically disposed when the transaction is disposed.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;This makes sense, but it is the opposite of what the documentation says on the second point on &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-9DFB5767-F8D6-4A88-87D6-9676C0189369" target="_blank" rel="noopener"&gt;this page&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If&amp;nbsp;adding it to the space means adding it to the database, then I don't need to dispose because of the third point, but you are mentioning the transaction, and the second point explicitly says the opposite of what you are saying. (I would say that point 3 ensures that Dispose is called, so I can ignore point 2).&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 15:00:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11590903#M10776</guid>
      <dc:creator>stefanome</dc:creator>
      <dc:date>2022-12-01T15:00:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591080#M10777</link>
      <description>&lt;P&gt;&lt;EM&gt;(Just exchanging opinions here, it's very clear that you are the one teaching and I'm the one learning&amp;nbsp;‌‌&lt;/EM&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;EM&gt;)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;This will work:&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;                var l1 = CreateLine(curSpace, p1, p2);
                var l2 = CreateLine(curSpace, p3, p4);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But simply doing this is simpler and clearer:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;                var l1 = new Line(p1, p2);
                curSpace.AppendEntity(l1);
                tr.AddNewlyCreatedDBObject(l1, true);
                var l2 = new Line(p3, p4);
                curSpace.AppendEntity(l2);
                tr.AddNewlyCreatedDBObject(l2, true);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;(I have removed some lines from the quoted code for clarity, and the server screwed up the formatting because it didn't like its own html)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I strongly disagree, the second snippet is not simpler and is not clearer!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It actually looks like the first lesson on what not to do if you want your code to be clear and maintainable. It looks like what you show to a beginner programmer when you introduce the functions and show how to execute multiple lines of code in one shot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my question I showed a simplified scenario where I create two new Lines in one spot, but I am thinking about tons of functions that I'm porting from another CAD to AutoCAD, and those functions take in input lists of existing entities, they analyze them, then add, remove or edit some of them. All the operations that those functions do are in one line. They can delete an existing entity, they can create a new one, they can change the color or other properties in another one. Triplicating the number of lines required to create a new entity just doesn't feel right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But this is just style. My question was about calling Dispose as shown on the documentation, and, as I understand from your answer, the example in the documentation is misleading and I can create this function if I want to.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 16:06:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591080#M10777</guid>
      <dc:creator>stefanome</dc:creator>
      <dc:date>2022-12-01T16:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591687#M10778</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/909070"&gt;@stefanome&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/909070"&gt;@stefanome&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;&lt;SPAN&gt;&lt;I&gt;&amp;nbsp;&amp;gt;&amp;gt;&amp;nbsp;&lt;/I&gt;. My question was about calling Dispose as shown on the documentation, and, as I understand from your answer, the example in the documentation is misleading and I can create this function if I want to.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Regarding the code at the link you referred to :&lt;/P&gt;&lt;P&gt;&lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-9DFB5767-F8D6-4A88-87D6-9676C0189369" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-9DFB5767-F8D6-4A88-87D6-9676C0189369&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;// Dispose an object with the using statement
using (&amp;lt;dataType&amp;gt; &amp;lt;object&amp;gt;  = &amp;lt;value&amp;gt;)
    // Do something here
}
 
// Manually dispose of an object with the Dispose method
&amp;lt;object&amp;gt;. Dispose ();&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, this code is misleading. The 2 statements are ALTERNTIVE Dispose methods. You don't need to use both.&lt;BR /&gt;This is stated in the header text on that page.&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; When creating new objects in .NET, you must properly free the objects from memory through the disposal process and garbage collection. &lt;FONT color="#0000FF"&gt;&lt;EM&gt;You use the&amp;nbsp;&lt;/EM&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT color="#0000FF"&gt;&lt;EM&gt;Dispose&amp;nbsp;method or the&amp;nbsp;Using&lt;/EM&gt;&lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT color="#0000FF"&gt;&lt;EM&gt;&amp;nbsp;statement to signal when an object is ready for garbage collection.&lt;/EM&gt; &lt;/FONT&gt;The&amp;nbsp;&lt;/SPAN&gt;Using&lt;SPAN&gt;&amp;nbsp;statement in most cases is the preferred method, as it makes the proper calls to close and dispose of the object when it is no longer needed. &amp;lt;&amp;lt;&amp;lt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 20:43:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591687#M10778</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2022-12-01T20:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591703#M10779</link>
      <description>&lt;P&gt;I was talking about this code on &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-47E8A12E-2ED4-4E78-ADA3-AAC9B4223C3C" target="_blank" rel="noopener"&gt;this page&lt;/A&gt;, where a new Line is created and added to the transaction inside an using block. My code was imitating this behavior.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;[CommandMethod("AddLine")]
public static void AddLine()
{
    // Get the current document and database
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
    Database acCurDb = acDoc.Database;

    // Start a transaction
    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
    {
        // Open the Block table for read
        BlockTable acBlkTbl;
        acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                                        OpenMode.ForRead) as BlockTable;

        // Open the Block table record Model space for write
        BlockTableRecord acBlkTblRec;
        acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                                        OpenMode.ForWrite) as BlockTableRecord;

        // Create a line that starts at 5,5 and ends at 12,3
        using (Line acLine = new Line(new Point3d(5, 5, 0),
                                      new Point3d(12, 3, 0)))
        {

            // Add the new object to the block table record and the transaction
            acBlkTblRec.AppendEntity(acLine);
            acTrans.AddNewlyCreatedDBObject(acLine, true);
        }

        // Save the new object to the database
        acTrans.Commit();
    }
}&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 01 Dec 2022 20:44:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591703#M10779</guid>
      <dc:creator>stefanome</dc:creator>
      <dc:date>2022-12-01T20:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591773#M10780</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/909070"&gt;@stefanome&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/909070"&gt;@stefanome&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;I think that this will not work because line is returned inside an using block, which means that it has been disposed by the time it is assigned to l1 or l2.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So, why do you create the new Line with a using statement ?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Because I was doing what the documentation says I should do. My code follows &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-47E8A12E-2ED4-4E78-ADA3-AAC9B4223C3C" target="_blank" rel="noopener"&gt;this example&lt;/A&gt;.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In the linked example nothing is done with the line outside of the (redundent) using statement used to create the new Line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/909070"&gt;@stefanome&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You do not need to dispose it in the CreateLine function. While an entity (or any DBObject) is added to a Transactiion, it will be automatically disposed when the transaction is disposed.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This makes sense, but it is the opposite of what the documentation says on the second point on &lt;A href="https://help.autodesk.com/view/OARX/2023/ENU/?guid=GUID-9DFB5767-F8D6-4A88-87D6-9676C0189369" target="_blank" rel="noopener"&gt;this page&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If&amp;nbsp;adding it to the space means adding it to the database, then I don't need to dispose because of the third point, but you are mentioning the transaction, and the second point explicitly says the opposite of what you are saying. (I would say that point 3 ensures that Dispose is called, so I can ignore point 2).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This page of the documentation is not very clear.&lt;/P&gt;
&lt;P&gt;We should create new DBObjects in a using statement to ensure the object to be disposed in case the object may not be added to the transaction (e.g. an exception occurs).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, this is not safe because if the user don't choose "Yes", the newly created Line won't be diposed.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;            using (var tr = db.TransactionManager.StartTransaction())
            {
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                var line = new Line(new Point3d(5, 5, 0), new Point3d(12, 3, 0));
                var pkr = ed.GetKeywords("\nAdd the line to databse [Yes/No]:", "Yes No");
                if (pkr.Status == PromptStatus.OK &amp;amp;&amp;amp; pkr.StringResult == "Yes")
                {
                    curSpace.AppendEntity(line);
                    tr.AddNewlyCreatedDBObject(line, true);
                }
                tr.Commit();
            }&lt;/LI-CODE&gt;
&lt;P&gt;Creating the Line in a using statement would be a solution to ensure the line to be disposed whatever the user reply.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;            using (var tr = db.TransactionManager.StartTransaction())
            {
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                using (var line = new Line(new Point3d(5, 5, 0), new Point3d(12, 3, 0)))
                {
                    var pkr = ed.GetKeywords("\nAdd the line to databse [Yes/No]:", "Yes No");
                    if (pkr.Status == PromptStatus.OK &amp;amp;&amp;amp; pkr.StringResult == "Yes")
                    {
                        curSpace.AppendEntity(line);
                        tr.AddNewlyCreatedDBObject(line, true);
                    }
                }
                tr.Commit();
            }&lt;/LI-CODE&gt;
&lt;P&gt;But immediately adding the Line to the Transaction is also a solution which ensure the Line to be disposed with the Transaction whatever le user reply.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;            using (var tr = db.TransactionManager.StartTransaction())
            {
                var curSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
                var line = new Line(new Point3d(5, 5, 0), new Point3d(12, 3, 0));
                curSpace.AppendEntity(line);
                tr.AddNewlyCreatedDBObject(line, true);
                var pkr = ed.GetKeywords("\nAdd the line to databse [Yes/No]:", "Yes No");
                if (pkr.Status != PromptStatus.OK &amp;amp;&amp;amp; pkr.StringResult == "Yes")
                {
                    line.Erase();
                }
                tr.Commit();
            }&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 01 Dec 2022 21:12:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591773#M10780</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-12-01T21:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591828#M10781</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/909070"&gt;@stefanome&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;&lt;EM&gt;(Just exchanging opinions here, it's very clear that you are the one teaching and I'm the one learning&amp;nbsp;‌‌&lt;/EM&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;EM&gt;)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This will work:&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;                var l1 = CreateLine(curSpace, p1, p2);
                var l2 = CreateLine(curSpace, p3, p4);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But simply doing this is simpler and clearer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;                var l1 = new Line(p1, p2);
                curSpace.AppendEntity(l1);
                tr.AddNewlyCreatedDBObject(l1, true);
                var l2 = new Line(p3, p4);
                curSpace.AppendEntity(l2);
                tr.AddNewlyCreatedDBObject(l2, true);&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;(I have removed some lines from the quoted code for clarity, and the server screwed up the formatting because it didn't like its own html)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I strongly disagree, the second snippet is not simpler and is not clearer!&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;"Simpler and clearer" was related to what &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8575899"&gt;@daniel_cadext&lt;/a&gt; said upper. &lt;BR /&gt;Creating and returning new DBObject from an external method may not be a good practice because from the top transaction code block we do not see nothing about the state of this newly created object:&lt;/P&gt;
&lt;P&gt;- Has it been added to the Database? (most buit-in methods which retun DBObject(s) let the reponsability to add them to the Datadase to the caller)&lt;/P&gt;
&lt;P&gt;- Is it opened for write?&lt;/P&gt;
&lt;P&gt;- Has it been disposed? As in your case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second snippet is less concise but it directly let you know the newly created lines have been added to the Database and so, are opened for write, without having to check the CreateLine called method.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To write more concise code I use to use some Extension methods library as &lt;A href="https://github.com/gileCAD/Gile.AutoCAD.Extension" target="_blank" rel="noopener"&gt;this one&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;using Gile.AutoCAD.Extension;
[...]
            using (var tr = Active.Database.TransactionManager.StartTransaction())
            {
                var curSpace = Active.Database.GetCurrentSpace(OpenMode.ForWrite);
                var l1 = new Line(p1, p2);
                curSpace.Add(l1);
                var l2 = new Line(p3, p4);
                curSpace.Add(l2);
                tr.Commit();
            }
            [...]&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 21:55:51 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591828#M10781</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-12-01T21:55:51Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591890#M10782</link>
      <description>&lt;P&gt;I have seen your repository with the extension methods, I love it!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I spent a little time on it this morning, trying to understand what makes an extension an extension. I searched for it on the documentation, but I couldn't figure it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I dropped it for the moment. It's too soon. I first want to get familiar with AutoCAD, its object model and how things work, then I will look into more advanced techniques. Extensions, Xrecords, Proxy objects, events, ... It will take some time to get familiar with all of them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Half the addins I created in the old CAD I'm coming from were running out of process. Mostly for performance reasons, I ended up creating a bunch of wrappers, something like Line2, Point2, Spline2 that wrap Line, Point and Spline and allow to do all the calculation locally (I had to write all the functions that do the calculation). At the end of the command Line2.Update() is called for each entity to make sure that the Line on the CAD side is updated, created or deleted, and everything is in sync with what the addin expects. If the Line is identical to the Line2 nothing happens, otherwise there is some out of process traffic. (No transactions there, much simpler)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I don't have the impact of working out of process, but I will still miss some functionalities, and creating extensions rather than wrappers sounds really yummy!&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 21:58:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591890#M10782</guid>
      <dc:creator>stefanome</dc:creator>
      <dc:date>2022-12-01T21:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591905#M10783</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/109424"&gt;@_gile&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;"Simpler and clearer" was related to what &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/8575899"&gt;@daniel_cadext&lt;/a&gt; said upper.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;It make sense.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm used to working without transactions and multiple databases or tables. In my previous life a line was a line. If I had one I could do whatever I wanted to do with it, without worrying about much.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 22:02:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591905#M10783</guid>
      <dc:creator>stefanome</dc:creator>
      <dc:date>2022-12-01T22:02:08Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a Line without calling Dispose?</title>
      <link>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591926#M10784</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/909070"&gt;@stefanome&lt;/a&gt;&amp;nbsp; a écrit&amp;nbsp;:&lt;BR /&gt;
&lt;P&gt;I spent a little time on it this morning, trying to understand what makes an extension an extension. I searched for it on the documentation, but I couldn't figure it out.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Extension methods are not specific to the AutoCAD API. They're part of .NET since C#3.0. You can see &lt;A href="https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/extension-methods" target="_blank" rel="noopener"&gt;this topic&lt;/A&gt; and &lt;A href="https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/how-to-implement-and-call-a-custom-extension-method" target="_blank" rel="noopener"&gt;this other one&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Dec 2022 22:12:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/how-do-i-create-a-line-without-calling-dispose/m-p/11591926#M10784</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2022-12-01T22:12:00Z</dc:date>
    </item>
  </channel>
</rss>

