Load / Unload AppDomain & memory

P

Perry

Hi,

I have a problem with the memory consumption of the AppDomain.Load and unload.

For example, when i run this code, the memory usage is increasing.

MessageBox.Show(string.Format("Before: {0}",GC.GetTotalMemory(true)));
for (int i = 0; i < 100; i++)
{
AppDomain appDom = AppDomain.CreateDomain(string.Format("SubDom_{0}",i));
AppDomain.Unload( appDom );
}
MessageBox.Show(string.Format("After: {0}",GC.GetTotalMemory(true)));


What could be the problem?

Best regard,



Perry
 
R

Richard Blewett [DevelopMentor]

I've done some experimenting with your code and the CLR Profiler.

Firstly, your 100 new appdomains has caused an additional allocation of 40k (on my system) but then I did just 1 and that got 40k too. So I then did 10000, guess what - 40k. I don't know the internals of exactly what is going on, but it would appear that a bunch of rooted infrastructure is allocated once you create an AppDomain but this overhead is static. In fact, if I remove all the AppDomain code and just run two Console.WriteLines I get and increase of 7k (I used a console app rather than a winforms one).

The largest allocation appear to be an internal hashtable and arraylist (about 10-15k each) However, I have no idea what they are used for.

The main lesson I think to draw from this however, is that there is an additional small set of allocations but they appear to be fixed no matter how many appdomains you create so on that basis, creating and unloading an appdomain doesn't cause a "leak". So on that basis there is no problem IMO.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

Hi, I have a problem with the memory consumption of the AppDomain.Load and unload. For example, when i run this code, the memory usage is increasing. MessageBox.Show(string.Format("Before: {0}",GC.GetTotalMemory(true)));
for (int i = 0; i < 100; i++)
{
AppDomain appDom = AppDomain.CreateDomain(string.Format("SubDom_{0}",i));
AppDomain.Unload( appDom );
}
MessageBox.Show(string.Format("After: {0}",GC.GetTotalMemory(true)));


What could be the problem?

Best regard,



Perry

This post contained attachments. By default, NewsGator will not download attachments, but can be configured to do so. If you wish to automatically download attachments for this newsgroup, go to NewsGator/Subscriptions, select this group and click Edit, and change the Options.


[microsoft.public.dotnet.languages.csharp]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top