473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Load / Unload AppDomain & memory

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

Nov 17 '05 #1
1 2730
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]
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Patrick Blackman | last post by:
I have a program that search the application path for all the Dll that implement a certain interface IText ,when a Dll with the interface is found ,I run a method called IText.Format() which works...
2
by: Lauren Hines | last post by:
Hello, I have read numerous post stating that the only way to unload an assembly (DLL in my case) is to create a separate AppDomain, load the assembly, then unload it by calling AppDomain.Unload....
4
by: John Wood | last post by:
Does anyone know if an AppDomain.Unload is guaranteed to free all memory /resources associated with the AppDomain before the method call returns?
3
by: Daniel | last post by:
How do i dynamicaly load and unload a C# dll at runtime
2
by: Razzie | last post by:
Hey all, I'm working on this project where I'm dynamically loading an assembly. Basically what I want is that I can just replace my old dll file with a new one without having to do anything...
2
by: brianbender | last post by:
I am trying to load and unload assemblies dynamically and call methods and properties when loaded into an Appdomain I can load assemblies all day in the current AppDomain without references and...
3
by: Frank Uray | last post by:
Hi all I have a problem with loading a assembly ... I am trying to do the following: - I have a directory with a dll (assembly) in it (not the currect dir.) - I am trying to load this assembly,...
2
by: chandu | last post by:
I want to load an assembly dinamically into another application with a button click. how to load and execute that dinamic assebly.. i tried like this copied that target assebly in bin folder...
1
by: chandu | last post by:
hello , i want to load and execute an existing dll in a applicaiton dynamically with out giving references etc... need to create separate appdomain or in same appdomain can i load and execute...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.