我StreamReader
在一个大文本文件(~300 MB)上使用 a 并在循环中调用 ReadLine() 最终会引发一个奇怪的问题ArgumentOutOfRangeException
:
Index and count must refer to a location within the buffer.
Parameter name: bytes
堆栈跟踪是:
at System.Text.DecoderNLS.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount,
Char[] chars, Int32 charIndex, Boolean flush)
at System.Text.DecoderNLS.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount,
Char[] chars, Int32 charIndex)
at System.IO.StreamReader.ReadBuffer()
at System.IO.StreamReader.ReadLine()
....
这是一些奇怪的记忆错误吗?它不会抛出OutOfMemoryException
,所以我有点迷路了。它发生在第 2000 行左右。到那时,即使它继续执行成功的 ReadLine(),它也会开始在其他地方抛出奇怪的异常。因此,某处可能存在内存泄漏,但是有什么特定的ReadLine()
或StreamReader
需要查看的吗?
我的文本文件中的每一行正好是 24 个字符长。