Dim output1 = System.IO.File.ReadAllLines(file).ToString
文件大小仅为1 GB。我的页面文件是128 GB。为什么内存不足?这是64位系统。
答案 0 :(得分:2)
因为OOM例外有许多不同的因素。从"Out Of Memory" Does Not Refer to Physical Memory开始。
“内存不足”错误几乎从未发生,因为没有足够的可用存储空间...而是发生“内存不足”错误,因为进程无法在其虚拟环境中找到足够大的连续未使用页面部分地址空间来执行请求的映射。
您还应该阅读CLR Inside Out - Investigating Memory Issues。
如果虚拟内存过于分散,则进程可能会耗尽虚拟空间。
因此,不要只查看文件大小和页面文件,还需要检查应用程序正在做什么,甚至检查系统上正在运行的其他进程。
答案 1 :(得分:1)
我是新手,但我在一些内存密集型应用程序中使用此代码段:
Declare Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal process As IntPtr, ByVal minimumWorkingSetSize As Integer, ByVal maximumWorkingSetSize As Integer) As Integer
Private Shared Sub _FlushMemory()
Try
GC.Collect()
GC.WaitForPendingFinalizers()
If (Environment.OSVersion.Platform = PlatformID.Win32NT) Then
SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)
Dim myProcesses As Process() = Process.GetProcessesByName(My.Application.Info.AssemblyName)
Dim myProcess As Process
For Each myProcess In myProcesses
SetProcessWorkingSetSize(myProcess.Handle, -1, -1)
Next myProcess
End If
Catch ex As Exception
End Try
End Sub
答案 2 :(得分:0)
还注意到你写的是什么。你不能将String Array(ReadAllLines)转换为String。
试试这个:
Dim output1 As String = IO.File.ReadAllText(file)
这会将文件内容作为 String
返回。如果这是你想要的。