MVC3内存溢出异常

问题描述:

部署有Telerik的扩展菜单的MVC3应用程序后,我注意到有它抛出一个OutOfMemoryException和之后的时间,应用程序冻结,没有用户大约一个小时后能够使用的应用程序,直到或者所以。MVC3内存溢出异常

我设法跟踪从Windows事件日志中的错误,下面是从事件中提取的错误之一的堆栈跟踪日志

异常信息:

Exception type: OutOfMemoryException 
Exception message: Exception of type 'System.OutOfMemoryException' was thrown. 
at System.RuntimeTypeHandle.ConstructName(RuntimeTypeHandle handle, 
Boolean nameSpace, Boolean fullInst, Boolean assembly, StringHandleOnStack retString) 
at System.RuntimeType.RuntimeTypeCache.ConstructName(String& name, Boolean nameSpace, Boolean fullinst, Boolean assembly) 
at System.RuntimeType.get_Name() 
at Telerik.Web.Mvc.Infrastructure.Implementation.ControllerTypeCache.<GetAllControllerTypes>b__d(Type type) 
at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext() 
at Telerik.Web.Mvc.Extensions.CollectionExtensions.AddRange[T](ICollection`1 instance, IEnumerable`1 collection) 
at Telerik.Web.Mvc.Infrastructure.Implementation.ControllerTypeCache.GetAllControllerTypes() 
at Telerik.Web.Mvc.Infrastructure.Implementation.ControllerTypeCache.<GetControllerTypesWithinNamespaces>b__4() 
at Telerik.Web.Mvc.Infrastructure.Implementation.Cache.Get[T](String key, Func`1 defaultValueFactory) 
at Telerik.Web.Mvc.Infrastructure.Implementation.ControllerTypeCache.GetControllerTypesWithinNamespaces(String controllerName, IEnumerable`1 namespaces) 
at Telerik.Web.Mvc.Infrastructure.Implementation.ControllerTypeCache.GetControllerTypes(String controllerName) 
at Telerik.Web.Mvc.Infrastructure.Implementation.ControllerDescriptorCache.ControllerDescriptorFactory(String controllerName, String areaName) 
at Telerik.Web.Mvc.Infrastructure.Implementation.ControllerDescriptorCache.<>c__DisplayClass1.<GetControllerDescriptor>b__0() 
at Telerik.Web.Mvc.Infrastructure.Implementation.Cache.Get[T](String key, Func`1 defaultValueFactory) 
at Telerik.Web.Mvc.Infrastructure.Implementation.ControllerDescriptorCache.GetControllerDescriptor(String controllerName, String areaName) 
at Telerik.Web.Mvc.Infrastructure.Implementation.AuthorizationContextCache.AuthorizationContextFactory(RequestContext requestContext, String controllerName, String actionName, String areaName) 
at Telerik.Web.Mvc.Infrastructure.Implementation.AuthorizationContextCache.<>c__DisplayClass1.<GetAuthorizationContext>b__0() 
at Telerik.Web.Mvc.Infrastructure.Implementation.Cache.Get[T](String key, Func`1 defaultValueFactory) 
at Telerik.Web.Mvc.Infrastructure.Implementation.AuthorizationContextCache.GetAuthorizationContext(RequestContext requestContext, String controllerName, String actionName, RouteValueDictionary routeValues) 
at Telerik.Web.Mvc.Infrastructure.Implementation.ControllerAuthorization.IsAccessibleToUser(RequestContext requestContext, String controllerName, String actionName, RouteValueDictionary routeValues) 
at Telerik.Web.Mvc.Infrastructure.Implementation.NavigationItemAuthorization.IsAccessibleToUser(RequestContext requestContext, INavigatable navigationItem) 
at Telerik.Web.Mvc.UI.NavigatableExtensions.<>c__DisplayClass2`1.<IsAccessible>b__1(T item) 
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate) 
at Telerik.Web.Mvc.UI.NavigatableExtensions.IsAccessible[T](IEnumerable`1 items, INavigationItemAuthorization authorization, ViewContext viewContext) 
at Telerik.Web.Mvc.UI.NavigationItemContainerExtensions.WriteItem[TComponent,TItem](TItem item, TComponent component, IHtmlNode parentTag, INavigationComponentHtmlBuilder`1 builder) 
at Telerik.Web.Mvc.UI.Menu.<>c__DisplayClass4.<WriteHtml>b__3(MenuItem item) 
at Telerik.Web.Mvc.Extensions.EnumerableExtensions.Each[T](IEnumerable`1 instance, Action`1 action) 
at Telerik.Web.Mvc.UI.Menu.WriteHtml(HtmlTextWriter writer) 
at Telerik.Web.Mvc.UI.ViewComponentBase.Render() 
at Telerik.Web.Mvc.UI.ViewComponentBuilderBase`2.Render() 
at ASP._Page_Views_Shared__Layout_cshtml.Execute() in e:\kidda\Views\Shared\_Layout.cshtml:line 34 
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() 
at System.Web.Mvc.WebViewPage.ExecutePageHierarchy() 
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) 
at System.Web.WebPages.WebPageBase.<>c__DisplayClass7.<RenderPageCore>b__6(TextWriter writer) 
at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) 
at System.Web.WebPages.WebPageBase.Write(HelperResult result) 
at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) 
at System.Web.WebPages.WebPageBase.PopContext() 
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) 
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance) 
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer) 
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) 
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) 
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) 
at System.Web.Mvc.Controller.ExecuteCore() 
at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) 
at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) 
at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5() 
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0() 
at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) 
at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() 
at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d() 
at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) 
at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) 
at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) 
at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) 
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

常见于堆栈跟踪到的所有错误堆栈跟踪是在_Layout.cshtml线34用下面的代码

<nav> 
    <div id="topMenu" > 
     <div style="width: 45%; float: right"> 
      @{ Html.Telerik().Menu() 
       .Name("Menu") 
       .Items(menu => 
        { 
         menu.Add() 
         .Text("Ngaari") 
         .Items(item => 
         { 
          item.Add().Text("List").Action("Index", "Ngaari"); 
          item.Add().Text("Statement").Action("Index", "Statement"); 
         }); 
         menu.Add() 
         .Text("Njia") 
         .Action("Index", "Njia"); 
         menu.Add() 
         .Text("Kiama") 
         .Action("Index", "Kiama"); 
         menu.Add() 
         .Text("Ngaari Type") 
         .Action("Index", "NgaariType"); 
         menu.Add() 
         .Text("Admin") 
         .Items(item => 
         { 
          item.Add().Text("List Users").Action("Index", "Account"); 
          item.Add().Text("Add User").Action("NewUser", "Account"); 
          item.Add().Text("Change Password").Action("ChangePassword", "Account"); 
         }); 
       }) 
       .Render(); 
       } 
     </div> 
    </div> 
</nav> 

该应用程序在Windows运行的绘制菜单2003 SP2,内存为4Gb,用户使用Mozilla Firefox访问系统。

我用Google搜索,并在Telerik的论坛和SOF并没有发现答案或相似的用户谁可能有类似的问题。

什么可能会造成这个错误,我该怎么去解决呢?

服务器上监控性能和内存使用解决了这个问题。 我意识到IIS与SQL Server的争用内存和存储是不是 频繁回收,这是什么导致问题

在从IIS 6 Administration的建议,我执行以下操作:

  • 设置应用程序池请求预设数量后回收
  • 集倍在低活动时间回收工作进程
  • 设定为由用在虚拟和物理存储器的量的帽3210应用

执行上述已完全消除该问题。