[英]Out of memory exception
我在程序啟動期間偶爾會出現內存異常。 堆棧跟蹤如下所示。 我只是在客戶機器上遇到此崩潰。
我應該遵循哪些步驟來確定根本原因?
[369][4/29/2011 18:32:15:343]-ERR -[ThreadId = 7916, UIFramework_ICEVisionPro_GUIExceptionHandler.LogException]-System.OutOfMemoryException: Out of memory.
at System.Drawing.Graphics.FromHdcInternal(IntPtr hdc)
at System.Drawing.BufferedGraphicsContext.CreateBuffer(IntPtr src, Int32 offsetX, Int32 offsetY, Int32 width, Int32 height)
at System.Drawing.BufferedGraphicsContext.AllocBuffer(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
at System.Drawing.BufferedGraphicsContext.AllocBufferInTempManager(Graphics targetGraphics, IntPtr targetDC, Rectangle targetRectangle)
at System.Drawing.BufferedGraphicsContext.Allocate(IntPtr targetDC, Rectangle targetRectangle)
at System.Windows.Forms.Control.WmPaint(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.UserControl.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
使用一個體面的內存分析器來幫助找到問題的根本原因
從上面的描述我明白你正在使用windows.forms。 Windows窗體程序中的內存泄漏可能是由於忘記在關閉表單時取消訂閱事件(訂閱者阻止處理表單)。 有一些文章和教程表明這是表單編程中非常常見的錯誤,因此您可以查看它。 當然,盡管如此,它可能不太適合你的情況(程序啟動時發生的故障)。
如果托管代碼中發生內存泄漏,則使用內存分析器可能是個好主意。 我主要使用ANTS Mem Profiler ,它具有很好的圖形和統計數據以及比大多數人更友好的用戶界面。
但是,如果泄漏發生在非托管代碼中(就像這里的這個人一樣),你就可以乘車了。 本文可能對您有所幫助。
總而言之,您可能需要大量閱讀才能了解.net應用程序中的內存管理,gc代的工作原理等等,所有這些都會占用您大量的時間。
祝好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.