我突然在两个不同的机器上运行两个程序时遇到了内存异常错误,尽管似乎有足够的内存,但仍然出现该问题。我在程序中创建了多个线程,所以不确定这是否适用于此论坛,但它是否与Visual Studio相关或者绝对是内存问题。其中一个程序在我的台式电脑上使用Visual Studio 2008和2GB RAM运行。另一个程序在使用Visual Basic 2008 Express和4GB RAM的Windows 2003服务器上运行。
现在,该模块需要读取一个大型XML文件并将其拆分并存储在字符串数组中。现在,块的数量最多可以达到10000个。我知道这很大,但我已经运行了一个多月了,从未遇到过这个问题。我注意到的唯一可能相关的问题是我在硬盘上的空间不足,但这很快就被清理解决了。哦,是的,我的机器处理器是2.13 GHZ的双核心。
这是一个控制台程序,可以进行多个Web请求,但是如上所述,内存问题只出现在一个特定的模块中。
Public Shared Function textLoad(ByVal _html As String) As Boolean
Try
//_html is the filestream that was read in
Dim defaultHeading = "xmlns:gnip=""http://www.gnip.com/schemas/2010"" xmlns=""http://www.w3.org/2005/Atom"""
Dim header_of_xml As String = "<?xml version=""1.0"" encoding=""utf-8""?>" & vbNewLine & "<entry " & defaultHeading & ">"
Dim footer_of_xml As String = "</entry>"
Dim entry As String = String.Empty
Dim xrs As XmlReaderSettings = New XmlReaderSettings()
Dim dupeArray As New ArrayList
Dim stringSplitter() As String = {"</entry>"}
//split the file content based on the closing entry tag
sampleResults = Nothing
sampleResults = _html.Split(stringSplitter, StringSplitOptions.RemoveEmptyEntries)
entryResults.Clear()
If getEntryId(sampleResults) Then
// the following loops seem clumsy but I wanted to dedupe the lists to //ensure that I am not adding duplicate entries and I do this by going to the getEntryID //method and extracting the ids and then comparing them below
For i As Integer = 0 To sampleResults.Count - 1
For j As Integer = 0 To idList.Count - 1
If sampleResults(i).Contains(idList.Item(j)) AndAlso Not dupeArray.Contains(idList.Item(j)) Then
dupeArray.Add(idList.Item(j))
entry = sampleResults(i)
我查看了任务管理器,以识别该程序使用的资源,以下是情况:
Parser.exe CPU = 34 内存使用 = 349,500 K
没有其他密集运行的任务
编辑 _-
确定问题的确切来源:
**sampleResults = _html.Split(stringSplitter, StringSplitOptions.RemoveEmptyEntries)**
有人能注意到这里有什么问题吗?