Re: Unloading appdomain and freeing memory

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi,

I saw this discussed before here.. under the topic how to unload assembly
and free the memory?

for you I just cut paste important postings..

Once loaded into a particular app domain an assembly cannot be unloaded.
You'd have to create a seperate app domain for each assembly (is this a
plugin thing perhaps) and then unload the app domains when they weren't
needed anymore.

--
Bob Powell [MVP]
Visual C#, System.Drawing

If you do that then why bother with using separate AppDomains? Just exit the
app when you want to free up the memory and unload assemblies

"navyliu" <navyliu@xxxxxxxxxxx> wrote in message

another guy said

I've discussed this problem with my friend and have another idea.
How about making the Assembly Loader as a Com Component?
I haven't test this. But I'll try to solve this problem.

Nirosh.

"RickN" <RickN@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:7F8A9E2D-D531-496D-97E4-2EB470D7A0A7@xxxxxxxxxxxxxxxx
I tried calling GC.Collect() and it does not reclaim the memory. I
verified
all objects created were set to null. An hour later it still has not been
reclaimed.

I think I might have read somewhere that .Net will not release the memory
for anything loaded, even if you unload the appdomain, until the main
process ends, but I can't put my fingers on that information. If it is
true,
it is an unfortunate lack of functionality for .Net, but important to
know,
because while I thought I was conserving memory by unloading the
appdomain,
then reloading it if needed later, I am in fact doubling the memory usage
by
unloading and reloading.

Can anyone verify that .Net 'should' be releasing the memory of a
dynamically loaded and then unloaded appdomain. If so, what's the trick.
If
not, what are the work arounds?

Thanks,
Rick

--
Rick


"Mark R. Dawson" wrote:

Hi RickN,
the memory will not be reclaimed until the Garbage Collector decides
that
it is time to reclaim the memory. If it does not feel that there is any
need
to since there is lots of available memory left then it won't run, it is
undeterministic.

You can force it to run if you want by calling GC.Collect() which will
collect objects from all generations that are eligable for being garbage
collected.

Mark.
--
http://www.markdawson.org


"RickN" wrote:

In my .Net 2.0 project I am creating a new appdomain, loading an
assembly and
then unloading the appdomain when finished.

However, even though the appdomain successfully unloads, the memory it
consumed when being added is not released. In fact, if I load the same
appdomain again, and then unload it, it doubles the amount of memory
consumed.

My main goal is to consume minimal memory, so how do I load a dll,
access
the assembly, unload it when finished, then regain the memory that was
consumed in the process.

Thanks,
Rick
--
Rick


.



Relevant Pages

  • Re: Reading assembly manifest without loading assembly
    ... reduce memory usage or to reduce developer usage. ... Cecil, especially when it is free, is the more sound choice from a cost ... But why don't load assembly to the new domain that can be unload? ... GY> GY> If you are loading theses assemblies into your own appdomain, ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Unloading appdomain and freeing memory
    ... the process ends, the memory is reclaimed. ... Once loaded into a particular app domain an assembly cannot be unloaded. ... plugin thing perhaps) and then unload the app domains when they weren't ... for anything loaded, even if you unload the appdomain, until the main ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: asp.net memory architecture question ...
    ... only unload the appdomain and start over. ... it taks no real memory only disk space (the code takes non - ... only global data on the page need to be swapped out), until the page is hit ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Passing to and back from Dialog
    ... When you create an instance of a class, its module is loaded into memory ... the public variables and methods you add to the code module of ... But a form also has a visual component. ... Between Load and Unload, all the controls and properties of the form are ...
    (microsoft.public.vb.general.discussion)
  • Re: Cant free the memory after unloading the userform
    ... You should use those commands in place of the one that you have. ... horrible hanging about in memory afterwards. ... Set myform = New YourFormName ... Unload myform ...
    (microsoft.public.word.vba.general)