An exception of type "System.OutOfMemoryException" is thrown

I suddenly get memory exception errors for two programs running on different machines, and although it seems that there is enough memory, it still appears. I create several threads in the program, so I'm not sure if this is suitable for this forum, but can it be something else related to the visual studio or is it definitely a memory problem. One program runs on my desktop using Visual Studio 2008 with 2 GB of RAM. The other runs on a Windows 2003 server with 4 GB of RAM, using the visual base 2008 Express. Now the module accepts a large XML file, which is read into a string, and then it is split and stored in an array of strings. Now the number of pieces can be up to 10,000. Now I know that it is big, but I have been working on it for more than a month and have never had a problem.The only other possible problem that I noticed was that I did not have enough space on my hard drive, but this was quickly resolved by cleaning. Oh yes, the processor for my machine is a duo core set at 2.13 GHz. This is a console program that creates several web records, but a memory problem only occurs in one particular module, as I explained above.

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)

taskmanager , , :

Parser.exe CPU = 34               MEM = 349 500 K

_-

, :

**sampleResults = _html.Split(stringSplitter, StringSplitOptions.RemoveEmptyEntries)**

- - ?

+3
5

Split . , . 10 000 , , , , ( , ). ? - :

  • ( ), .
  • , "".
  • . ( , , - ?).
  • html ( # 1), , .

, .

+9

, OOM , , .

  • 2 32-
  • ,

OOM. , GDI + , . OOM.

+4

, .NET? ( Windows 2008 R2 " " > " " ) " .NET 0", " 1", " " Gen 2 " ". , , .

, , 85 000 . , . , LOH GC, , LOH. CLR LOH , , OOM.

, LOH OOM. , 100 , LOH, 10 , 5 , 85 . CLR , 15 LOH. 86 , OOM. , , 10 , , 95 . 86 , CLR LOH, CLR 86 , OOM. 86 , 5 . , Google LOH .

, , , , , . , , 85 000 , , LOH.

+2

. 64- . , :

1. , ( ) ref . .

2. AppDomain . .

3. Whenever you can - instead of creating objects and strings (WebRequests / Response) use the same memoryStream or buffer again and again. Highlight the one with the maximum size (even * 2 the maximum expected size). distribution (using new) Stream / StringBuilder / string / classes / Buffers Choke a bunch.

+1
source

This article may be useful, it describes something that may throw an exception:

http://kb.insideofthefuture.com/Assuntos/outofmemoryexception.htm

0
source

Source: https://habr.com/ru/post/1790192/


All Articles