如何解决类型'System.OutOfMemoryException'的异常被抛出?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (1701)

我有以下问题:

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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks) +567
   System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection) +192
   System.Reflection.Assembly.Load(String assemblyString) +35
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +123

[ConfigurationErrorsException: Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective) +11569328
   System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory() +485
   System.Web.Configuration.AssemblyInfo.get_AssemblyInternal() +79
   System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig) +337
   System.Web.Compilation.BuildManager.CallPreStartInitMethods() +280
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +1167

[HttpException (0x80004005): Exception of type 'System.OutOfMemoryException' was thrown.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +11702064
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +141
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +4870277

如何解决?

提问于
用户回答回答于

当某些进程(如将大量数据加载到内存流和系统内存)无法存储太多数据时,通常会出现此问题。尝试通过发出命令清除临时文件夹

start -> run -> %temp%

用户回答回答于

在调试模式下运行

在开发和调试应用程序时,你通常会将web.config文件中的debug属性设置为true,并将你的DLL编译为调试模式。但是,在将应用程序部署到测试或生产之前,应该在发布模式下编译组件,并将debug属性设置为false。

在调试模式下运行时,ASP.NET在许多级别上工作方式不同。实际上,当你在调试模式下运行时,GC将允许你的对象保持更长的运行时间(直到范围结束),因此在调试模式下运行时总会看到更高的内存使用量。

在调试模式下运行的另一个经常未实现的副作用是,通过webresource.axd和scriptresource.axd处理程序提供的客户端脚本不会被缓存。这意味着每个客户端请求都必须下载任何脚本(如ASP.NET AJAX脚本),而不是利用客户端缓存。这可能导致性能大幅下降。

资料来源:

http://blogs.iis.net/webtopics/archive/2009/05/22/troubleshooting-system-outofmemoryexceptions-in-asp-net.aspx

所属标签

可能回答问题的人

  • uncle_light

    5 粉丝518 提问6 回答
  • 优惠活动秘书

    0 粉丝2 提问6 回答
  • 最爱开车啦

    8 粉丝503 提问6 回答
  • 天使的炫翼

    17 粉丝531 提问5 回答

扫码关注云+社区

领取腾讯云代金券