Can I (and do I ever want to) set the maximum heap size in .net?

前端 未结 4 894
执笔经年
执笔经年 2020-12-01 07:50

Coming from a java background, one of the things I am used to is telling the JVM what the maximum heap size should be. If the running program tries to swallow more than is

4条回答
  •  有刺的猬
    2020-12-01 08:30

    No, it doesn't apply in .NET. The heap does indeed keep growing until it can't grow any more. (Obviously this is "after attempting to recover memory through GC, grow the heap".) Basically there isn't nearly as much tuning available in the .NET GC as in Java. You can choose the server GC or the client one, and I think there's an option for turning on/off the concurrent GC (I'll find links in a minute) but that's basically it.

    EDIT: It seems there's a little more to it, although not a huge amount. Rick Minerich's blog entry on GC settings and the subsequent one seem to know rather more than I do about the matter. They're probably a good starting point for any further investigation - but they're mostly flags rather than the sort of memory limits available in JVMs.

    EDIT: Pop's answer raises a good point - I've been assuming a "normal" CLR hosting model (i.e. not under your control). If you want to go to the effort of hosting it yourself, you're likely to get a lot more control - at the cost of the extra work of hosting it. I can't say I've ever looked into that side of things.

提交回复
热议问题