I am getting OOM exceptions in an ASP.Net application and have found that this is probably caused by heavy string operations such as s1 = s1.Replace()
and s1 = s1.SubString()
at the time where the exceptions are thrown.
Is it possible to get OOM exceptions just from those operations if they are happening sequentially? The number of requests are not a lot, but is it possible that the GC does not release memory in time before a new allocation on the heap is made?
In other words: can the following code give OOM exceptions开发者_运维问答 or will the GC release the large amount of unreferenced strings before we get to OOM exception?
string s = "hello world";
while (true)
{
s = s.Replace("h", "h");
}
This isn't really an answer to your question, more a suggestion of where to look if you want to debug difficult memory issues.
I've found Tess Ferrandez an invaluable source of information on those hard to squash bugs. She uses Windbg, which has quite a steep learning curve - but it WILL allow you to work out what is taking up the memory and why.
I'd suggest starting with her labs if you are interested in debugging this, or maybe the ASP.Net memory investigation post might set you on the right course
精彩评论