<?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: Shall I dispose Result Buffer in this sample function ? in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3370059#M56905</link>
    <description>&lt;P&gt;Thanks chief, It was a great explanation and now I feel more comfortable. Didn't have a clue about all these. Like a blind person walking .&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just one more question and I am done. I work with Visual studio and and don't know how to activate appropriate debug message to tell me I have to dispose. I attach the setting I have as image. Let me know please if with this setting I should see that warning you mentioned.&lt;/P&gt;&lt;P&gt;&lt;IMG align="center" title="2012-03-13_2333.png" alt="2012-03-13_2333.png" src="http://forums.autodesk.com/t5/image/serverpage/image-id/23389i3CEDBDD58F68173A/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Mar 2012 03:35:45 GMT</pubDate>
    <dc:creator>JanetDavidson</dc:creator>
    <dc:date>2012-03-14T03:35:45Z</dc:date>
    <item>
      <title>Shall I dispose Result Buffer in this sample function ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3366643#M56901</link>
      <description>&lt;P&gt;I have seen lots of samples for resultbuffer objects. And I am not quite undestand where I have to dispose and where not to. I know It doens't hurt to dispose it anyways. But I am a woman and don't like to see extra unnessary lines in my application.Everything should be perfect. So someone explain it for me. Let's say below Funciton . Do I need a dispose ? &amp;nbsp;Thanks . Regards .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  Function test(ByVal Myobjid As ObjectId) As Boolean
        Dim MyDwg As Document = Application.DocumentManager.MdiActiveDocument
        Using Tr As Transaction = MyDwg.TransactionManager.StartTransaction

            Dim mydbObj As DBObject = Tr.GetObject(Myobjid, OpenMode.ForRead)
            If TypeOf mydbObj Is BlockReference Then
                Dim BR As BlockReference = TryCast(mydbObj, BlockReference)
                If BR.IsDynamicBlock Then
                    Dim myrb As ResultBuffer = mydbObj.GetXDataForApplication("BlahBlah")
                    If myrb.AsArray(1).Value.ToString.StartsWith("TEST") Then
                        Tr.Commit()
                        Return True
                    End If
                End If
            End If
            Tr.Commit()
        End Using
        Return False
    End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Mar 2012 17:03:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3366643#M56901</guid>
      <dc:creator>JanetDavidson</dc:creator>
      <dc:date>2012-03-11T17:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: Shall I dispose Result Buffer in this sample function ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3367965#M56902</link>
      <description>&lt;P&gt;In my opinion, yes, because it is not associated with the transaction, so your using statement will not dispose of it for you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A bigger question for me is wether or not you should be disposing BR.&amp;nbsp; mydbObj will get disposed by the using statement on your transaction, but I'm not sure about BR.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are using AuotCAD 2009 or later, I would suggest this:&lt;/P&gt;&lt;PRE&gt;Function test(ByVal Myobjid As ObjectId) As Boolean
    Dim MyDwg As Document = Application.DocumentManager.MdiActiveDocument
    Using Tr As Transaction = MyDwg.TransactionManager.StartTransaction
        'Dim mydbObj As DBObject = Tr.GetObject(Myobjid, OpenMode.ForRead)
        'If TypeOf mydbObj Is BlockReference Then
        If Myobjid.ObjectClass.Name = "AcDbBlockReference" then
            Dim BR As BlockReference = Tr.GetObject(Myobjid, OpenMode.ForRead)
            If BR.IsDynamicBlock Then
                Using myrb As ResultBuffer = mydbObj.GetXDataForApplication("BlahBlah")
                    If myrb.AsArray(1).Value.ToString.StartsWith("TEST") Then
                        Tr.Commit()
                        Return True
                    End If
	        End Using
            End If
        End If
        Tr.Commit()
    End Using
    Return False
End Function&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The using statement will ensure the result buffer gets disposed wether it is your test value, or not.&amp;nbsp; And using ObjectId.ObjectClass will allow you to type test for BlockReference without opening the object into memory.&amp;nbsp; That is the part that only works in 2009 or later.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2012 19:09:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3367965#M56902</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2012-03-12T19:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: Shall I dispose Result Buffer in this sample function ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3368383#M56903</link>
      <description>&lt;P&gt;Thanks Chief,&lt;/P&gt;&lt;P&gt;I will use your code. I didn't know about "ObjectClass" that is good trick .&lt;/P&gt;&lt;P&gt;But still I am confused. because once I removed all &amp;nbsp;" disposed " function for result buffer and nothing happened. I worked with drawing for 2 hours . No crash . Audit &amp;nbsp;didn't show anything. that I why I am not sure why do I need it ? if there is a need for dispose how and where phisically &amp;nbsp;it will affect ? Do you know ?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2012 01:46:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3368383#M56903</guid>
      <dc:creator>JanetDavidson</dc:creator>
      <dc:date>2012-03-13T01:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: Shall I dispose Result Buffer in this sample function ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3369461#M56904</link>
      <description>&lt;P&gt;For the most part, in my experience, not calling dispose will not cause a crash, unless you try to access the object after it falls out of scope which would cause a crash even if you did call dispose.&amp;nbsp; The result of not calling dispose is that the object remains in memory, and it is not flagged for garbage collection.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My general rule to avoid that memory usage is to call dispose (or use a "using" directive)&amp;nbsp;on every object that implements iDisposable, and I have even implemented iDisposable on some of my own classes.&amp;nbsp; If you open an object using Transaction.GetObject(ID, openmode), then when you dispose the transaction, the object will be disposed as well, which is why you usually don't see explicit .Dispose calls on objects opened that way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The exception to that rule is that you never call dispose on an object you didn't create.&amp;nbsp; For example the active document, or the TransactionManager, or any Database that is open in the editor (unless you close it first).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you are using Visual Studio, and you have the appropriate debug messages enabled, you will see messages in the output window that say "Forgot to call dispose?".&amp;nbsp; My goal is to never see any of those messages.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Mar 2012 18:17:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3369461#M56904</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2012-03-13T18:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: Shall I dispose Result Buffer in this sample function ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3370059#M56905</link>
      <description>&lt;P&gt;Thanks chief, It was a great explanation and now I feel more comfortable. Didn't have a clue about all these. Like a blind person walking .&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just one more question and I am done. I work with Visual studio and and don't know how to activate appropriate debug message to tell me I have to dispose. I attach the setting I have as image. Let me know please if with this setting I should see that warning you mentioned.&lt;/P&gt;&lt;P&gt;&lt;IMG align="center" title="2012-03-13_2333.png" alt="2012-03-13_2333.png" src="http://forums.autodesk.com/t5/image/serverpage/image-id/23389i3CEDBDD58F68173A/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2012 03:35:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3370059#M56905</guid>
      <dc:creator>JanetDavidson</dc:creator>
      <dc:date>2012-03-14T03:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Shall I dispose Result Buffer in this sample function ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3371123#M56906</link>
      <description>&lt;P&gt;The settings I was referring to are in a different location, in the options dialog (which you can to as shown below, from the debug pulldown, or also from the Tools pulldown -&amp;gt;Options)&amp;nbsp;Then you have to make sure Show All Settings is checked in the bottom left.&amp;nbsp; Go to Debugging-&amp;gt;Output Window.&amp;nbsp; image shows how mine were set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I didn't see an option in there that jumped out at me for the dispose messages, I fiddled around a bit, and turned all of them off.&amp;nbsp; Then I tested again, and I still got my "Forgot to call dispose?"&amp;nbsp;message that you see in the image.&amp;nbsp; Obviously I have a missing dispose call somewhere that I need to find &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&amp;nbsp; But more importantly, you might not need to mess with these options because like I said, even with all of them off I still got my message.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forums.autodesk.com/t5/image/serverpage/image-id/23491i3F81EAC7F3C4196C/image-size/original?v=mpbl-1&amp;amp;px=-1" align="center" title="DebugProps.png" alt="DebugProps.png" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2012 18:21:28 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3371123#M56906</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2012-03-14T18:21:28Z</dc:date>
    </item>
    <item>
      <title>Re: Shall I dispose Result Buffer in this sample function ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3371139#M56907</link>
      <description>&lt;P&gt;I just noticed that if you right-click in the output window, you get direct access to toggle the "General Output Settings" plus one more called "Program Output".&amp;nbsp; If you turn off Program output, pretty much everything goes away, including the Dispose messages.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2012 18:28:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3371139#M56907</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2012-03-14T18:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: Shall I dispose Result Buffer in this sample function ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3371595#M56908</link>
      <description>&lt;P&gt;Much appreciated .&lt;/P&gt;&lt;P&gt;&amp;nbsp;I had them off. After I turned them on. I have 200 lines. My God ?!!&lt;/P&gt;&lt;P&gt;What did you do to me Chief ? Just Joking.&lt;/P&gt;&lt;P&gt;This is going to be a good weekend, finding all 200 Boo BOOs.&lt;/P&gt;&lt;P&gt;Thanks for all help&lt;/P&gt;&lt;P&gt;Janet&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2012 23:32:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3371595#M56908</guid>
      <dc:creator>JanetDavidson</dc:creator>
      <dc:date>2012-03-14T23:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Shall I dispose Result Buffer in this sample function ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3371603#M56909</link>
      <description>&lt;P&gt;Keep in mind, if you forget to dispose something that is inside a loop, you will get one of those messages for every time through the loop, so you probably&amp;nbsp;don't have 200&amp;nbsp;Boo Boos to find.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Mar 2012 23:40:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3371603#M56909</guid>
      <dc:creator>chiefbraincloud</dc:creator>
      <dc:date>2012-03-14T23:40:08Z</dc:date>
    </item>
    <item>
      <title>Re: Shall I dispose Result Buffer in this sample function ?</title>
      <link>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3371721#M56910</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not convinced that the ResultBuffer needs to be disposed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Reference :&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.theswamp.org/index.php?topic=39724.msg450130#msg450130" target="_blank"&gt;http://www.theswamp.org/index.php?topic=39724.msg450130#msg450130&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.theswamp.org/index.php?topic=27651.msg332416#msg332416" target="_blank"&gt;http://www.theswamp.org/index.php?topic=27651.msg332416#msg332416&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;I'd LIKE to see some qualified direction from AutoDesk regarding this issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Kerry&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Mar 2012 03:08:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/shall-i-dispose-result-buffer-in-this-sample-function/m-p/3371721#M56910</guid>
      <dc:creator>kerry_w_brown</dc:creator>
      <dc:date>2012-03-15T03:08:21Z</dc:date>
    </item>
  </channel>
</rss>

