我有一个预编译的web应用程序(32位),在此内存使用量缓慢上升,直到我得到OutOfMemoryExceptions。使用分析器,我注意到主要的怀疑是System.Web.VirtualPath对象中的字符串,这些字符串依次存储在System.Web.Compilation.BuildManager对象中的_localResourcesAssemblies哈希表中。
这些条目似乎以大约50 MB的批次被添加,每4-6小时一次。我被卡住了--我不知道在添加这些条目的BuildManager中调用了什么。查看条目,它们包含匹配属性路由控制器(或有效路由路径的父路径)的有效路由的路径。
应用程序目录中不应更改任何文件。
我建立了一个简单的web应用程序,并提供了类似的路径,以查看我是否能够重现这个问题,但我还无法在测试应用程序上重现这个问题。
对于如何找到BuildManager (密封类,可能是单例)对象中调用的内容,有什么想法吗?
发布于 2016-08-19 17:00:15
解决办法:删除Microsoft.AspNet.WebPages nuget包(以及依赖它的页面,包括Microsoft.AspNet.WebApi.HelpPage包)。
我们最终得到了一个堆栈跟踪,内存不足来自问题的真正原因(我们的大部分跟踪都在我们自己的代码中,一次分配几MB )。堆栈跟踪张贴在下面。
我们能够找到动态添加WebPages HTTP模块并注册回调,该回调将每个url路径添加到BuildManager中的缓存中,并且由于32位内存空间和大量的唯一路径,这最终会使我们耗尽内存。
正如所承诺的那样,最终能够将我们引向问题起因的堆栈痕迹:
Exception type: OutOfMemoryException
Exception message: Exception of type 'System.OutOfMemoryException' was thrown.
at System.Collections.Hashtable.rehash(Int32 newsize, Boolean forceNewHashCode)
at System.Collections.Hashtable.expand()
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at System.Collections.Hashtable.set_Item(Object key, Object value)
at System.Web.Compilation.BuildManager.EnsureFirstTimeDirectoryInit(VirtualPath virtualDir)
at System.Web.Compilation.BuildManager.GetBuildResultFromCacheInternal(String cacheKey, Boolean keyFromVPP, VirtualPath virtualPath, Int64 hashCode, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultFromCacheInternal(VirtualPath virtualPath, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
at System.Web.Compilation.BuildManager.GetObjectFactory(String virtualPath, Boolean throwIfNotFound)
at System.Web.WebPages.BuildManagerWrapper.GetObjectFactory(String virtualPath)
at System.Web.WebPages.BuildManagerWrapper.ExistsInPrecompiledSite(String virtualPath)
at System.Web.WebPages.BuildManagerWrapper.Exists(String virtualPath)
at System.Web.WebPages.VirtualPathFactoryManager.Exists(String virtualPath)
at System.Web.WebPages.DefaultDisplayMode.GetDisplayInfo(HttpContextBase httpContext, String virtualPath, Func`2 virtualPathExists)
at System.Web.WebPages.DisplayModeProvider.GetDisplayInfoForVirtualPath(String virtualPath, HttpContextBase httpContext, Func`2 virtualPathExists, IDisplayMode currentDisplayMode, Boolean requireConsistentDisplayMode)
at System.Web.WebPages.DisplayModeProvider.GetDisplayInfoForVirtualPath(String virtualPath, HttpContextBase httpContext, Func`2 virtualPathExists, IDisplayMode currentDisplayMode)
at System.Web.WebPages.WebPageRoute.GetRouteLevelMatch(String pathValue, String[] supportedExtensions, Func`2 virtualPathExists, HttpContextBase context, DisplayModeProvider displayModeProvider)
at System.Web.WebPages.WebPageRoute.MatchDefaultFiles(String pathValue, String[] supportedExtensions, Func`2 virtualPathExists, HttpContextBase context, DisplayModeProvider displayModes, String currentLevel)
at System.Web.WebPages.WebPageRoute.MatchRequest(String pathValue, String[] supportedExtensions, Func`2 virtualPathExists, HttpContextBase context, DisplayModeProvider displayModes)
at System.Web.WebPages.WebPageRoute.DoPostResolveRequestCache(HttpContextBase context)
at System.Web.WebPages.WebPageHttpModule.OnApplicationPostResolveRequestCache(Object sender, EventArgs e)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)https://stackoverflow.com/questions/38797799
复制相似问题