2014-09-23 66 views
3

我得到這個錯誤,想不通爲什麼它正在發生而應用程序沒有使用多少內存

我使用Windows 8.1的64位32 GB的RAM內存

你怎麼能得到的System.OutOfMemoryException

應用程序是32位,使用任務管理器時只有大約400 MB,更少的時候檢查與GC.GetTotalMemory(false)

如何調試此錯誤的原因?

C#WPF .NET 4.5應用

這裏最大壓縮字符串中的數據庫中的數據(322 KB):http://www.monstermmorpg.com/reciprocal/zipped.txt

該最大數據(4837 KB)的在這裏未壓縮字符串:http://www.monstermmorpg.com/reciprocal/unzipped.txt

這裏解壓字符串功能

private static string Un_GZip_String(string compressedText) 
{  
     using (var memoryStream = new MemoryStream()) 
     { 
      byte[] gZipBuffer = Convert.FromBase64String(compressedText); 
      int dataLength = BitConverter.ToInt32(gZipBuffer, 0); 
      memoryStream.Write(gZipBuffer, 4, gZipBuffer.Length - 4); 

      var buffer = new byte[dataLength]; 

      memoryStream.Position = 0; 
      using (var gZipStream = new GZipStream(memoryStream, System.IO.Compression.CompressionMode.Decompress)) 
      { 
       gZipStream.Read(buffer, 0, buffer.Length); 
      } 

      return Encoding.UTF8.GetString(buffer); 
     } 
} 

http://i.stack.imgur.com/fepMs.png

enter image description here

+0

可能是DecompressString方法中的一個錯誤。進入它,看看它實際上拋出異常的線? – Quintium 2014-09-23 21:55:24

+0

字符串有多大,未壓縮版本有多大? – 2014-09-23 21:55:28

+0

@JonSkeet都很小。這裏解壓縮的字符串:http://pastebin.com/AGrabX2s - 解壓縮函數是gzip – MonsterMMORPG 2014-09-23 21:56:43

回答

0

我建議你下載螞蟻性能分析器:

http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/

這將牽制正是爲什麼你得到了內存異常,並有30天的免費試用 - 那應該有足夠的時間讓你弄清楚。

正如有人在評論中所說的那樣,它可能是大型對象堆,因爲它可能會很快失去控制。性能分析器將很快告訴你什麼是問題。

+0

我試過微軟的visual studio性能分析器,甚至是那個小夾子。因爲創建和處理的對象太多了。它就像每秒數千次。 – MonsterMMORPG 2014-09-24 20:01:27

相關問題