Is there something in .NET that corresponds to java -Xmx
memory size allocation?
views:
1255answers:
3Have a look at this thread:Maximum Heap size - only solution is to plugin more memory.
This thread looks like exactly what you're wanting.
If I'm reading the MVP's post correctly, on a 32-bit system you're limited to 1.5GB heap size no matter what, of which you get all as soon as the process starts. On a 64-bit system your heap is essentially unlimited, I don't think any mainstream server or PC can hold as much physical memory as a 64-bit process can address.
As far as I've found, there is no simple way to control the size of the help of a .Net app using the CLR.
The link in @Dave's answer only half answers the question. When I've researched this same issue, the response is "The heap grows to use all available memory" as if that is the only reason you'd want to control the max heap size.
On (typically Java) server environments, you don't want a badly behaving app to hog memory at the expense of other hosted apps. A simple solution is to limit the amount of memory that the app can use for it's heap. This is accomplished with Java's -Xmx argument so you can guarantee the app won't use more than what is planned, e.g. -Xmx256M. Since allocating memory on the heap during initialization can slow the apps startup, Java uses the -Xms arg to allow apps that do alot of object creation during initialization to start out with a large block of heap instead of the JVM contantly resizing the heap as it goes.
.Net's CLR does not have this ability. I suspect it is because .Net's CLR is not a virtual machine. The CLR happens to be an API (quite comprehensive, I might add) which serves as an adapter to native .dlls which equate to an approach much more like an executable when it comes to memory management.
I've asked this question about SharePoint development and did hear that it might be possible to control the heapsize through the use of IIS modules called Web Apps whereby you can tell IIS to limit the memory of a given web app. I wonder if this is because IIS has customized routines which replace/override new()/malloc()/etc and thus can provide this type of control to client apps. That means that standalone .Net apps are out of luck unless you want to write a custom memory manager in C++ and create an interface for .Net