问题描述
c#winform程序,我采用的多线程模式,程序运行几十个小时,(也有个别的机器,运行4-5个小时),报以下错误:查了很久,没发现程序哪个地方内存出现问题了:有关调用实时(JIT)调试而不是此对话框的详细信息,请参见此消息的结尾。**************异常文本**************System.OutOfMemoryException:引发类型为“System.OutOfMemoryException”的异常。在System.Reflection.Assembly._nLoad(AssemblyNamefileName,StringcodeBase,EvidenceassemblySecurity,AssemblylocationHint,StackCrawlMark&stackMark,BooleanthrowOnFileNotFound,BooleanforIntrospection)在System.Reflection.Assembly.nLoad(AssemblyNamefileName,StringcodeBase,EvidenceassemblySecurity,AssemblylocationHint,StackCrawlMark&stackMark,BooleanthrowOnFileNotFound,BooleanforIntrospection)在System.Reflection.Assembly.InternalGetSatelliteAssembly(CultureInfoculture,Versionversion,BooleanthrowOnFileNotFound)在System.Resources.ResourceManager.GetSatelliteAssembly(CultureInfolookForCulture)在System.Resources.ResourceManager.InternalGetResourceSet(CultureInfoculture,BooleancreateIfNotExists,BooleantryParents)在System.Resources.ResourceManager.InternalGetResourceSet(CultureInfoculture,BooleancreateIfNotExists,BooleantryParents)在System.Resources.ResourceManager.GetString(Stringname,CultureInfoculture)在System.Drawing.SR.GetString(Stringname)在System.Drawing.SafeNativeMethods.Gdip.StatusException(Int32status)在System.Drawing.Graphics.CheckErrorStatus(Int32status)在System.Drawing.Graphics.DrawImage(Imageimage,RectangledestRect,Int32srcX,Int32srcY,Int32srcWidth,Int32srcHeight,GraphicsUnitsrcUnit,ImageAttributesimageAttrs,DrawImageAbortcallback,IntPtrcallbackData)在System.Drawing.Graphics.DrawImage(Imageimage,RectangledestRect,Int32srcX,Int32srcY,Int32srcWidth,Int32srcHeight,GraphicsUnitsrcUnit,ImageAttributesimageAttr,DrawImageAbortcallback)在System.Drawing.Graphics.DrawImage(Imageimage,RectangledestRect,Int32srcX,Int32srcY,Int32srcWidth,Int32srcHeight,GraphicsUnitsrcUnit,ImageAttributesimageAttr)在System.Windows.Forms.ControlPaint.DrawBackgroundImage(Graphicsg,ImagebackgroundImage,ColorbackColor,ImageLayoutbackgroundImageLayout,Rectanglebounds,RectangleclipRect,PointscrollOffset,RightToLeftrightToLeft)在System.Windows.Forms.Control.PaintBackground(PaintEventArgse,Rectanglerectangle,ColorbackColor,PointscrollOffset)在System.Windows.Forms.Control.PaintBackground(PaintEventArgse,Rectanglerectangle)在System.Windows.Forms.Control.OnPaintBackground(PaintEventArgspevent)在System.Windows.Forms.ScrollableControl.OnPaintBackground(PaintEventArgse)在System.Windows.Forms.Control.PaintTransparentBackground(PaintEventArgse,Rectanglerectangle,RegiontransparentRegion)在System.Windows.Forms.Control.PaintBackground(PaintEventArgse,Rectanglerectangle,ColorbackColor,PointscrollOffset)在System.Windows.Forms.Control.PaintBackground(PaintEventArgse,Rectanglerectangle)在System.Windows.Forms.Control.OnPaintBackground(PaintEventArgspevent)在System.Windows.Forms.ScrollableControl.OnPaintBackground(PaintEventArgse)在System.Windows.Forms.ToolStrip.OnPaintBackground(PaintEventArgse)在System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgse,Int16layer)在System.Windows.Forms.Control.WmPaint(Message&m)在System.Windows.Forms.Control.WndProc(Message&m)在System.Windows.Forms.ScrollableControl.WndProc(Message&m)在System.Windows.Forms.ToolStrip.WndProc(Message&m)在System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)在System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)在System.Windows.Forms.NativeWindow.Callback(IntPtrhWnd,Int32msg,IntPtrwparam,IntPtrlparam)
解决方案
本帖最后由 wylj20052006 于 2015-05-25 14:57:42 编辑
解决方案二:
资源泄漏:1.查内存泄漏,检查反复申请,特别是在线程中循环处理的部分2.查Handle等句柄的申请释放推荐使用.NetMemoryProfiler工具来查
解决方案三:
真晦气,找到问题了,使用了一个第三方的计算工具,我程序里每秒调一次,调用一次增加1M的内存占用,4小时候就溢出了
解决方案四:
调用完记得dispose不要一直new,不释放