2015-10-14 55 views
1

我們有一個問題,在這裏我們可以有一些OutOfMemoryException不使用全部內存/限制時內存不足

我們將檢查我們如何減少內存使用量,但我的問題是爲什麼我現在得到它在這一點

根據Memory Profiler和Windows任務管理器,應用程序權重只有 400MB。

對於我所瞭解的(confirmed here),對於32位應用程序,限制應該在2GB左右。我的電腦有16GB內存,並有大量內存(超過4GB)。

那麼,爲什麼我現在得到這個錯誤?

我的問題不是關於爲什麼我的應用程序的內存在增長,而是爲了瞭解爲什麼它現在已經在發生。 我覺得這個限制不是固定的,但我找不到任何參考。

調用堆棧,如果有幫助:

System.OutOfMemoryException: Out of memory. 
    at System.Drawing.Graphics.CheckErrorStatus(Int32 status) 
    at System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height) 
    at Nevron.GraphicsCore.NBitmapGdiRenderSurface.Paint(Object sender, PaintEventArgs e, l1ll11Il1 contentPainter) 
    at Nevron.Chart.WinForm.NControlView.Paint(Object sender, PaintEventArgs e) 
    at Nevron.Chart.WinForm.NChartControl.OnPaint(PaintEventArgs e) 
    at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer) 
    at System.Windows.Forms.Control.WmPaint(Message& m) 
    at System.Windows.Forms.Control.WndProc(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 

編輯 我得到了同樣的異常與一個完全不同的堆棧跟蹤:

System.ComponentModel.Win32Exception (0x80004005): Not enough storage is available to process this command 
    at DevExpress.Utils.Drawing.XtraBufferedGraphicsContext.CreateCompatibleDIB(IntPtr hdc, IntPtr hpal, Int32 ulWidth, Int32 ulHeight, IntPtr& ppvBits) 
    at DevExpress.Utils.Drawing.XtraBufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height) 
    at DevExpress.Utils.Drawing.XtraBufferedGraphicsContext.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle) 
    at DevExpress.Utils.Drawing.XtraBufferedGraphicsContext.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle) 
    at DevExpress.Utils.Drawing.XtraBufferedGraphicsContext.Allocate(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle) 
    at DevExpress.Utils.Drawing.XtraBufferedGraphicsContext.Allocate(Graphics targetGraphics, Rectangle targetRectangle) 
    at DevExpress.XtraBars.Docking2010.Views.BaseViewPainter.Draw(GraphicsCache cache, Rectangle clip) 
    at DevExpress.XtraBars.Docking2010.Views.BaseView.Draw(GraphicsCache cache, Rectangle clip) 
    at DevExpress.XtraBars.Docking2010.DocumentManager.PaintCore(Graphics g, Rectangle bounds) 
    at DevExpress.XtraBars.Docking2010.DocumentManager.DevExpress.XtraBars.Docking2010.IDocumentsHostOwner.Paint(Graphics g) 
    at DevExpress.XtraBars.Docking2010.DocumentsHost.OnPaint(Graphics g) 
    at DevExpress.XtraBars.Docking2010.DocumentsHost.DoPaint(Message& m) 
    at DevExpress.XtraBars.Docking2010.DocumentsHost.WndProc(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) 
    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) 
    at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) 
+0

你可以發佈渲染圖像的代碼或其削減版本嗎?這可能是問題。見http://stackoverflow.com/q/16055667/1239433 –

+0

不幸的是,我沒有它,我們使用Nevron繪製一個繪圖(實際上,繪製20個繪圖並行),我們只是添加一個值到系列,在這裏複製)。 – J4N

+0

你如何重現這個問題?你打開和關閉窗體和窗戶嗎? –

回答

4

這可能是你所看到的結果的內存碎片。這種情況發生在總共有2GB空閒空間的情況下,但是最大的內存空間比這個數量要小得多,例如200MB。然後你嘗試分配一個400MB的塊並得到一個內存不足的例外。另外,如果你正在使用GDI +,它在各種情況下都有拋出內存異常的惡習,其中大部分與內存無關。

剛剛看過你的蹤跡,它可能很容易就是我提到的那些GDI +的一些奇怪的東西。在過去,我遇到過這種情況,比如加載位圖時的文件權限。這就是我會檢查我是否是你。不是專門的文件權限,而是已知GDI +會吐出OOM異常的情況。

+0

我們正在處理大量的數據,所以我們必須做很多創造一些類/自毀的,怎麼能我確定這是因爲內存碎片?解決這個問題的方向是什麼? – J4N

+0

我真的不能添加任何內容到Ned已發佈的內容。你可以用谷歌的.Net內存分析器,看看產生了什麼。 – dandan78

+0

這使得像2天出頭的我正在運行的內存分析器:(。我沒有看到LOH增長如果這就是我應該尋找。 – J4N

5

一種可能性是你的大對象堆已經變得碎片化了。即它有足夠的空間,但沒有足夠大的空間來滿足大對象的分配。

儘管看起來有辦法做one off compaction now,但LOH通常不會被壓縮。

如果確實是這個問題,避免LOH碎片化的一種方法是通過使用大對象池,當你完成它們而不是讓GC處理它們時,它們會返回到池中。

+0

好了,我怎麼能確認這是問題或沒有? – J4N

+0

嘗試USI在ANTS Profiler的試用版本中,它具有檢測LOH碎片的功能https://www.simple-talk.com/dotnet/.net-framework/large-object-heap-compaction-should-you-use-it/ –

+0

我擁有該工具的許可證;)我僅在「會話概覽」 - >「大對象堆大小」中看到過,其中有2MB已用空間和12MB未使用對象空間。這是一個問題嗎?還有什麼我可以檢查螞蟻爲此? – J4N