Reputation: 6184
I have a website where some user can upload his dll. I need to create an instance from this dll and call a specific method. Moreover, I need to do it with several dll's in 1 process, so it is not an option for me to use System.Diagnostics.Process.
Is there a way to determine how much memory does this method call use or limit it in my application runtime? Thanks in advance for any help
Upvotes: 10
Views: 20040
Reputation: 4592
If you use .NET 4.0 have a look at MemoryFailPoint.
Another suggestion: .NET 4.0 now offers facilities to supervise the memory consumption of an AppDomain (AppDomain.MonitoringIsEnabled Property). You can for instance use the main AppDomain to poll and tear down an AppDomain, if it uses too much memory.
Upvotes: 5
Reputation: 26756
Memory usage in .Net is very difficult to gauge - It will depend on a lot of factors like whether garbage collection run, how much of the framework has been loaded, etc.
You can look at memory usage on a per-process level using performance counters
Assuming for a moment you've already considered the security implications of running a users code in a semi-trusted environment, you need to use an AppDomain to load the DLL - That way it can be unloaded without restarting the whole website / worker pool
Upvotes: 9
Reputation: 1153
Could you use GC.GetTotalMemory as an alternative to track your memory usage?
http://msdn.microsoft.com/en-us/library/system.gc.gettotalmemory.aspx
Upvotes: 4
Reputation: 65534
Seriously you cannot go past Red Gates Ants Memory Profiler - free 14 day trial...
Upvotes: 0