如何解决“Out of Memory Exception” c#console应用程序中的错误 [英] How do I solve the "Out of Memory Exception" error in c# console Application

查看:147
本文介绍了如何解决“Out of Memory Exception” c#console应用程序中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此控制台应用程序永不停止。始终处于运行模式。为什么没有自动垃圾收集呢?



请帮帮我。

谢谢。

This console application never stop. always in running mode. Why automatic garbage collection not happening?

Please help me.
Thanks.

推荐答案

垃圾收集器可能仍在运行并正在运行,但您没有释放正在使用的任何内存。这个程序读取一个相当大的文件到内存中可以处理的内容,所以如果这个文件大于可用的内存量,那么你需要查看另一种访问这个文件的方法。



两种调试技术可以帮助解决这个应用程序永远不会完成的原因:



1)放入大量的System.Diagnostics.Debug.WriteLine (特定行标识符);代码中的消息并查看输出窗口,以查看卡住时正在执行的行。看看为什么循环永远不会终止。提示:在for(;;)循环中包含索引作为调试消息的一部分。



2)在应用程序成功运行之前注释掉大量代码。当它重新引入注释代码,直到它没有完成并找到你的问题代码。
The garbage collector is probably still running and working, but you are not releasing any of the memory that you are using. This program reads what is presumable a rather large file into memory to process, so if this file is larger then the amount of memory available then you will need to look into another method of accessing this file.

Two debugging techniques that can help work out why this application never finishes are:

1) Put lots of System.Diagnostics.Debug.WriteLine("Specific line identifier"); messages in the code and look at the output window to see what lines are being executed when it gets stuck. Look at why the loop never terminates. Tip: in a for (;;) loop include the index as part of the debug message.

2) Comment out huge swathes of code until the application successfully runs through. When it does re-introduce the commented code until it does not finish and you have found your problem code.


这篇关于如何解决“Out of Memory Exception” c#console应用程序中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆