Well, thatβs all relative. The process on Windows as a whole is an expensive resource, but only if you compare it with an operating system such as Unix. Common Windows resource sharing rules apply to a managed process. In physical memory, there will be only one instance for the code in the CLR, the JIT compiler, and any assembly that contains all .NET framework assemblies. The Windows memory manager simply displays the same pages in all processes using these DLLs.
What is not common is private bytes, you can see this number with a tool like SysInternal Process Explorer. Large parts of private bytes in a .NET process:
- pile of garbage
- stacks used by threads, default 1 MB piece
- any static variables used by code loaded in the appdomain
- code that was just generated at the time of assembly that was not changed
- personal data for CLR and jitter.
Obviously, using ngen.exe can significantly reduce the number of private bytes if you use assembly in more than one process. AppDomain is a .NET way to reduce process costs and still achieve the isolation level that is widely used in custom CLR hosts such as ASP.NET and SQL Server. If you have the ability to run code in a thread and run it in another process, then the thread should always be selected.
source share