<?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: Releasing Memory After Netloaded Command is Complete in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591871#M68297</link>
    <description>{quote}&lt;BR /&gt;
&lt;BR /&gt;
Since our .NET applications are 'owned' by AutoCAD, AutoCAD takes care of &lt;BR /&gt;
handling memory.  This can be best demonstrated by failing to Dispose of &lt;BR /&gt;
objects that should be disposed of.  It usually doesn't take long before &lt;BR /&gt;
AutoCAD complains (crashes).  That is an indication that AutoCAD attempts to &lt;BR /&gt;
use Memory it felt should be available but wasn't.&lt;BR /&gt;
&lt;BR /&gt;
{quote}&lt;BR /&gt;
&lt;BR /&gt;
No, not really.&lt;BR /&gt;
&lt;BR /&gt;
AutoCAD sometimes crashes when you don't call Dispose() on certain objects &lt;BR /&gt;
(namely DBObjects) because code called from their finalizer is not &lt;BR /&gt;
thread-safe, and the garbage collector calls the finalizer in a non-AutoCAD &lt;BR /&gt;
thread where that code cannot execute. Essentially, it is the same issue &lt;BR /&gt;
that you see when trying to use most AutoCAD APIs from a thread spwaned by &lt;BR /&gt;
your application (it will fail).&lt;BR /&gt;
&lt;BR /&gt;
You can read more about this by searching this newsgroup. It has been &lt;BR /&gt;
discussed here a number of times in greater depth.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");</description>
    <pubDate>Thu, 19 Nov 2009 22:04:34 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2009-11-19T22:04:34Z</dc:date>
    <item>
      <title>Releasing Memory After Netloaded Command is Complete</title>
      <link>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591866#M68292</link>
      <description>There may be something basic here I'm missing.  But it seems that when my applications are netloaded into the current autocad session and the application is run, the amount of memory resources increase.  This is expected while the application is running, but once finished and closed out, it should at least drop back down to what it was after the netload command, but before the application command.&lt;BR /&gt;
&lt;BR /&gt;
My assumption here is that since AutoCAD has taken ownership of the application, it is hanging on to its resources and not letting go.&lt;BR /&gt;
&lt;BR /&gt;
Any thoughts?  I have a pretty intense application that I don't want to continue pulling those kinds of resources and I don't want to have to tell the user that they'll have to close AutoCAD and start a new session after having used it.</description>
      <pubDate>Thu, 19 Nov 2009 13:35:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591866#M68292</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-19T13:35:01Z</dc:date>
    </item>
    <item>
      <title>Re: Releasing Memory After Netloaded Command is Complete</title>
      <link>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591867#M68293</link>
      <description>I'm guessing you are looking at the Processes Tab in the Task Manager.  Right?&lt;BR /&gt;
&lt;BR /&gt;
This article may be of interest to you and others.  It basically indicates the fact that Windows manages memory allocated to applications when it is necessary, not simply because we dispose of an Object or our code stops executing.&lt;BR /&gt;
&lt;BR /&gt;
http://www.itwriting.com/dotnetmem.php&lt;BR /&gt;
&lt;BR /&gt;
Jerry</description>
      <pubDate>Thu, 19 Nov 2009 15:21:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591867#M68293</guid>
      <dc:creator>jerrywinters</dc:creator>
      <dc:date>2009-11-19T15:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: Releasing Memory After Netloaded Command is Complete</title>
      <link>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591868#M68294</link>
      <description>Okay... So I've begun to poke around various books around here and found one that discusses the .NET framework garbage collection process.  I'm still reading through it, so there maybe more to come to light.  But from what I can tell so far, the .NET Framework triggers a Garbage Collection process which utilizes a Garbage Collector object to mark objects designated as being reclaimed from the memory heap allocated for your application.  This collection process can occur at any time (minutes or even hours) after you set your variable/object to nothing.  This seems to fit in part with your article.&lt;BR /&gt;
&lt;BR /&gt;
Your article pretty well takes a stance of not worrying about it.  So with all this information my question can be restated a little differently:&lt;BR /&gt;
&lt;BR /&gt;
1.)  AutoCAD takes ownership of your .NET application.  AutoCAD itself is based (in most part) on the C++ language structure.  Will the .NET Framework's Garbage Collector find and release my objects when appropriate or will it always take releasing AutoCAD for this to occur?&lt;BR /&gt;
&lt;BR /&gt;
2.)  If the answer to question 1.) is No, then does it make sense to force garbage collection as a last call following command execution?&lt;BR /&gt;
&lt;BR /&gt;
3.)  Since AutoCAD takes ownership of the .NET application (before and after command execution so long as it's been "netloaded"), will any memory residue slow AutoCAD processes?&lt;BR /&gt;
&lt;BR /&gt;
It may be that in the end, I really don't have a lot to worry about.  But AutoCAD uses our .NET applications differently than say a stand-alone windows application ran outside of the AutoCAD namespace.  I don't want to create a situation where our users are using a lot of custom code applications that would eventually degrate performance over the course of that AutoCAD session.  Any thoughts or comments?</description>
      <pubDate>Thu, 19 Nov 2009 15:42:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591868#M68294</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-19T15:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Releasing Memory After Netloaded Command is Complete</title>
      <link>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591869#M68295</link>
      <description>Those are great questions!&lt;BR /&gt;
&lt;BR /&gt;
Since our .NET applications are 'owned' by AutoCAD, AutoCAD takes care of handling memory.  This can be best demonstrated by failing to Dispose of objects that should be disposed of.  It usually doesn't take long before AutoCAD complains (crashes).  That is an indication that AutoCAD attempts to use Memory it felt should be available but wasn't.&lt;BR /&gt;
&lt;BR /&gt;
Based on my understanding (which, well, you're taking your chances), attempting to force Garbage Collection is not recommended.  The amount of memory 'allocated' by Windows may increase as your program runs but the amount of memory 'used' by AutoCAD does not necessarily increase.&lt;BR /&gt;
&lt;BR /&gt;
It would be interesting to create a benchmark to do some testing on this.  I would expect to see 'allocated' memory rise as a program runs, stay level after the program has run.  I would not expect to see AutoCAD run any slower as a result.  Then we should see 'allocated' memory drop as Windows sees a need to allocate memory to a different process.&lt;BR /&gt;
&lt;BR /&gt;
At any rate, if a program is releasing resources correctly, that's all we can do.  I'll see if I can put something together a little later today.&lt;BR /&gt;
&lt;BR /&gt;
I'm certain others with more experience on this particular issue would have some valuable input as well.&lt;BR /&gt;
&lt;BR /&gt;
Jerry</description>
      <pubDate>Thu, 19 Nov 2009 15:58:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591869#M68295</guid>
      <dc:creator>jerrywinters</dc:creator>
      <dc:date>2009-11-19T15:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Releasing Memory After Netloaded Command is Complete</title>
      <link>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591870#M68296</link>
      <description>I haven't looked into it yet, so perhaps the answer is not hard to find, but this thread got me curious about recovering memory from any custom netload(ed) add on code that is no longer needed.  Is there a way to "unload" the add-on code?</description>
      <pubDate>Thu, 19 Nov 2009 16:07:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591870#M68296</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-19T16:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Releasing Memory After Netloaded Command is Complete</title>
      <link>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591871#M68297</link>
      <description>{quote}&lt;BR /&gt;
&lt;BR /&gt;
Since our .NET applications are 'owned' by AutoCAD, AutoCAD takes care of &lt;BR /&gt;
handling memory.  This can be best demonstrated by failing to Dispose of &lt;BR /&gt;
objects that should be disposed of.  It usually doesn't take long before &lt;BR /&gt;
AutoCAD complains (crashes).  That is an indication that AutoCAD attempts to &lt;BR /&gt;
use Memory it felt should be available but wasn't.&lt;BR /&gt;
&lt;BR /&gt;
{quote}&lt;BR /&gt;
&lt;BR /&gt;
No, not really.&lt;BR /&gt;
&lt;BR /&gt;
AutoCAD sometimes crashes when you don't call Dispose() on certain objects &lt;BR /&gt;
(namely DBObjects) because code called from their finalizer is not &lt;BR /&gt;
thread-safe, and the garbage collector calls the finalizer in a non-AutoCAD &lt;BR /&gt;
thread where that code cannot execute. Essentially, it is the same issue &lt;BR /&gt;
that you see when trying to use most AutoCAD APIs from a thread spwaned by &lt;BR /&gt;
your application (it will fail).&lt;BR /&gt;
&lt;BR /&gt;
You can read more about this by searching this newsgroup. It has been &lt;BR /&gt;
discussed here a number of times in greater depth.&lt;BR /&gt;
&lt;BR /&gt;
-- &lt;BR /&gt;
http://www.caddzone.com&lt;BR /&gt;
&lt;BR /&gt;
AcadXTabs: MDI Document Tabs for AutoCAD&lt;BR /&gt;
Supporting AutoCAD 2000 through 2010&lt;BR /&gt;
&lt;BR /&gt;
http://www.acadxtabs.com&lt;BR /&gt;
&lt;BR /&gt;
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");</description>
      <pubDate>Thu, 19 Nov 2009 22:04:34 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/releasing-memory-after-netloaded-command-is-complete/m-p/2591871#M68297</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2009-11-19T22:04:34Z</dc:date>
    </item>
  </channel>
</rss>

