非托管资源泄露

来源:互联网 发布:炮王 知乎 编辑:程序博客网 时间:2024/06/01 10:15
2013/08/07
现象:
         RSS信息播放库运行两天后出现“内存不足”现象
BUG:
         Exception:内存不足。
System.OutOfMemoryException
Stack Trace:
   在 System.Drawing.Graphics.CheckErrorStatus(Int32 status)
   在 System.Drawing.Graphics.DrawImage(Image image, Int32 x, Int32 y, Int32 width, Int32 height)
   在 System.Drawing.Bitmap..ctor(Image original, Int32 width, Int32 height)
   在 System.Drawing.Bitmap..ctor(Image original)
   在 Nova.Rss.RssToImage.RssItemAsImg(RssItemInfo item, Int32 wndWidth, Bitmap& bmp)
   在 Nova.Rss.RssToImage.RssToMultiLinesImage(RssInfo rssInfo, Int32 wndWidth, Color backColor, List`1& imgList)
   在 Nova.Rss.RssToImage.RssToScreenImageIgnoreHalfWord(RssInfo rssInfo, Size wndSize, Int32 leftMargin, Color backColor, List`1& imgList)
解决过程:
         使用工具:.Net Memory Profiler工具运行库,逐个接口查看内存泄漏变量及源。
资料:
     http://msdn.microsoft.com/zh-cn/magazine/cc163491.aspx
结论:
      对于非托管资源,要非常注意资源的释放,容易产生内存泄漏的类型有:网络连接类,文件操作类,GDI+,流,COM组件等。
0 0