Reputation: 6516
Today, a production server at my work started to get this OutOfMemoryException, but as far as I know, there has not been any code updates to the website.
I pasted the stack trace below, but any ideas on what might be happening? Basically, this header control, downloads a portions of a website from a remote server and includes it as part of the HTML.
Server Error in '/' Application. Exception of type 'System.OutOfMemoryException' was thrown. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
Source Error:
Line 58: else
Line 59: {
Line 60: thisHeader = Cache[headerCacheKey].ToString() + "\n<!-- pulled from cache -->\n";
Line 61: }
Line 62: if (!String.IsNullOrEmpty(thisHeader))
Source File: ...
Stack Trace:
[OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.]
System.String.Concat(String str0, String str1) +66
ASP.controls_header_ascx.Page_Load(Object sender, EventArgs e) in ...:60
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
System.Web.UI.Control.OnLoad(EventArgs e) +132
System.Web.UI.Control.LoadRecursive() +66
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Control.LoadRecursive() +191
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428
Upvotes: 0
Views: 5525
Reputation: 5128
The line that the runtime is pointing you to (Line 60
I believe) is not necessarily a cause of System.OutOfMemoryException
. There might be some code that feeds the web cache with lots of information and doesn't release that information when it's no longer "valid" or "actual".
Anyway I suggest you to read these two articles first:
The second article helped me ALOT when I faced the same problem one day. Actually now I prefer windbg
over other (often proprietary) software to find out where is a memory leak in the software.
You could also try using one of these very helpful tools to find out what causes memory leaks:
In general I think it's a good practice to examine the software execution process using a memory profiler before deploying the software on the production environment.
Upvotes: 4
Reputation: 12596
Are you are looping in Page_Load and within that loop concatenating a string? String concatenation is VERY slow and with each concatenation a new string object is allocated and put on the heap. System.Text.StringBuilder
is a much more efficient way of doing this sort of operation. Note: if only concatenating a few short strings it is not an issue, but if you believe it'll go beyond that, then StringBuilder is your friend.
HTH
Upvotes: 3