We've been running into daily OutOfMemoryExceptions in our ASP.Net 4.0 website. We suspect one of the problems is LOH fragmentation so we've been looking into code changes that would allocate memory more efficiently.
For example, we're generating a large string (2mb) that we want to return to the browser. Paging the data is not an option.
Is it more efficient to:
Response.Write(bigString)
orResponse.Write(smallString)
If I follow option 1 then I've got the one big string taking space on the LOH that then is copied to the Response object's internal buffer. So this seems like I've now got 2 big blocks on the LOH at least temporarily.
If I follow option 2 then I'm dealing with lots of small strings that get garbage collected and only the one large block on the LOH for the Response object's buffer.
So it seems to me option 2 is better.
Am I understanding this correctly?
The server has 4gb of Ram and is running Windows 2003 32bit. This is the only site running on the server. So each process has a 4gb address space but only 2gb is usable. We start getting OOM errors when virtual bytes hits about 1.8Gb and then we recycle the site which resolves the problem for about 24 hours. Private bytes varies between 500-800mb. I don't think the problem is that we are running out of physical memory.
Without knowing the implementation, my answer may be a little less helpful than what I would hope. I'll venture a go, though.
If it were me, I would leverage two tactics:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With