How to determine memory usage in my .NET application

I have a website where some users can upload their DLL. I need to create an instance from this DLL and call a specific method. Moreover, I need to do this with several DLLs in 1 process, so for me it is not an option to use System.Diagnostics.Process.

Is there a way to determine how much memory this method uses to use or limit it in my application runtime? Thanks in advance for any help

+6
memory-management
source share
4 answers

Memory usage in .Net is very difficult to evaluate - it will depend on many factors, such as the start of garbage collection, how much the framework is loaded, etc.

You can see the memory usage at the level of each process using performance counters.

Assuming that you have already considered the security implications for running user code in a semi-reliable environment, you need to use AppDomain to load the DLL - this way you can unload it without restarting the entire website / work pool

+7
source share

If you are using .NET 4.0, check out MemoryFailPoint .

Another suggestion: .NET 4.0 now offers tools for controlling memory consumption of the AppDomain ( AppDomain.MonitoringIsEnabled Property ). For example, you can use the main AppDomain to poll and stall the AppDomain if it uses too much memory.

+5
source share

Could you use GC.GetTotalMemory as an alternative to track your memory usage?

http://msdn.microsoft.com/en-us/library/system.gc.gettotalmemory.aspx

+3
source share

Seriously, you can't get past the Red Gates Ants Memory Profiler - a free 14-day trial ...

0
source share

All Articles