Can I configure my C# application to limit its memory consumption to, say, 200MB?
IOW, I don’t want to wait for the automatic GC (which seems to allow the heap to grow much more than actually needed by this application).
I know that in Java there’s a command line switch you can pass to the JVM that achieves this.. is there an equivalent in C#?
p.s.
I know that I can invoke the GC from code, but that’s something I would rather not have to do periodically. I’d rather set it once upon startup somehow and forget it.
I am not aware of any such options for the regular CLR. I would imagine that you can control this if you implement your own CLR host.
However, I disagree in your assessment of how the heap grows. The heap grows because your application is allocating and holding on to objects.
There are a couple of things you can do to limit the memory usage. Please see this question for some input: Reducing memory usage of .NET applications?