惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
Google DeepMind News
Google DeepMind News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Proofpoint News Feed
Recent Announcements
Recent Announcements
MongoDB | Blog
MongoDB | Blog
U
Unit 42
云风的 BLOG
云风的 BLOG
Recorded Future
Recorded Future
G
Google Developers Blog
I
InfoQ
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
Jina AI
Jina AI
量子位
宝玉的分享
宝玉的分享
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 聂微东
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
美团技术团队
The Hacker News
The Hacker News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
D
Darknet – Hacking Tools, Hacker News & Cyber Security
T
Tailwind CSS Blog
博客园 - 司徒正美
博客园 - 叶小钗
Hugging Face - Blog
Hugging Face - Blog
P
Palo Alto Networks Blog
博客园_首页
阮一峰的网络日志
阮一峰的网络日志
博客园 - 【当耐特】
Spread Privacy
Spread Privacy
The GitHub Blog
The GitHub Blog
Y
Y Combinator Blog
Vercel News
Vercel News
Martin Fowler
Martin Fowler
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Forbes - Security
Forbes - Security
Attack and Defense Labs
Attack and Defense Labs
Google DeepMind News
Google DeepMind News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
P
Privacy International News Feed
G
GRAHAM CLULEY
The Last Watchdog
The Last Watchdog
C
Cyber Attacks, Cyber Crime and Cyber Security
AI
AI
V2EX - 技术
V2EX - 技术

博客园 - 思无邪

Silverlight内存泄露(八)样式 Silverlight内存泄露(七)Command Silverlight内存泄露(六)MEF等Ioc框架引起内存泄露-ExportLifetimeContext Silverlight内存泄露(五)MEF等Ioc框架引起内存泄露-PartCreationPolicy Silverlight内存泄露(四)解决内存泄露 Silverlight内存泄露(二)检测内存泄露 从火狐放弃依据特性更新版本说起 Silverlight内存泄露(二)解决内存泄露之Dispose误用 Silverlight IReader阅读器第二版 silverlight阅读器——面向领域的浏览器(二)——Silverlight阅读器架构 silverlight阅读器——起源面向领域的浏览器——概念 silverlight异步陷阱(二)循环 silverlight 异步陷阱(一)不能Remove事件处理程序 IReader Silverlight电子阅读器介绍开源项目 silverlight在线阅读器(二):为silverlight增加gb2312编码 silverlight在线阅读器(一):介绍 新建立一个类似于CuteEditor的项目,希望有人参加。发布一个测试版本的dll 从控件开发的角度看几个editor控件,Freetextbox,radtoolbar,abouteditor,cuteeditor 想做一个关于word解析和HtmlEditor的项目,希望有人加入 cuteEditor6.0的破解方式与Cuteeditor6.0的脚本调试
Silverlight内存泄露(一)序
思无邪 · 2011-04-12 · via 博客园 - 思无邪

不知道有多少人遇到过Silverlight程序内存狂涨的状况,点击几个按钮、跳转几个页面程序的内存使用量一直上升。

即使最简单的程序,用silverlight模板,创建一个导航程序,跳转几次页面silverlight内存使用也再增加。

托管代码内存由GC回收,在silverlight、wpf出现之前内存泄露出现的比较少,但是silverlight程序却很容易发生内存泄露。

最近一直再处理Silverlight内存泄露问题,但网上相关内容很少,一些经验和大家分享。

托管代码内存泄露原因

GC介绍:NET中GC小记

http://www.cnblogs.com/aaronbao/archive/2010/04/04/1692925.html

GC并不能保证不发生内存泄露,GC只会会根据自身算法回收GC认为不再使用的对象,由于程序bug,有些对象在GC看来仍然被使用,但是这些对象都不再使用了应该被回收。

托管代码可能发生内存泄露的情况:

  • Static references
  • Event with missing unsubscription
  • Static event with missing unsubscription
  • Dispose method not invoked
  • Incomplete Dispose method

文章中使用Dispose注销事件,个人认为这种使用方式是错误的,至少不被推荐使用,下面会讨论这个问题。

详细内容参考下面文章:.net程序如何避免内存泄露

http://msdn.microsoft.com/en-us/library/ee658248.aspx

WPF可能发生内存泄露的情况

Leak Description

Developer Error

NETFX 3.0

NETFX 3.5

NETFX 3/5 sp1

Improper Use of Event Handlers

X

     

Improper Use of Data Binding

X

     

Improper Use of Command Binding

X

X

X

X

Improper Use of Static Event Handlers

X

     

Use BitmapImage in ImageSource

 

X

X

 

Multiple Use of BitmapImage

   

X

 

Use of downloaded BitmapImage

 

X

   

CMilChannel leaks if initial HWND destroyed on XP

 

X (XP only)

X (XP only)

X (XP only)

ShutdownListener leaked for each thread using Binding

 

X

X

X

Create and Destroy WriteableBitmap on XP in HW

     

X (XP in HW Only)

SW Viewport 3D w/ VisualBrush, WB, etc. leaks on XP

     

X (XP in HW Only)

参考:http://blogs.msdn.com/b/jgoldb/archive/2008/02/04/finding-memory-leaks-in-wpf-based-applications.aspx

Silverlight内存泄露原因:

1. 由silverlight本身的bug导致

期待Silverlight新版本的能解决问题。但是如果真对性能要求很高,可以找出引起内存泄露的代码或者xaml,换一种实现方式。这部分不多讨论,下面链接讨论了silverlight引起内存泄露的情况http://forums.silverlight.net/forums/t/171739.aspx

2. 程序bug,除了上述引起内存泄露的情况外,Silverlight引起内存泄露的情况还有:

a) Command引起的内存泄露

b) Style、Xaml引起的内存泄露

c) 弱引用引起的内存泄露——按道理弱引用不会产生内存泄露,但实际情况并非如此,弱引用看似简单,但其实却很难用好。哪怕及时释放掉了实际的对象,但弱引用数组还是会继续持有引用,这就导致了内存泄漏。可能和silverlight的bug有关。参看wpf 弱引用补丁http://www.infoq.com/cn/news/2010/06/WPF-Memory-Leaks

d) MEF等第三方注入库可能引起内存泄露

文章列表

当前想到可能包含下面的文章,有时间就会写:

1. 如何检测SIlverlight内存泄露

2. 如何解决内存泄露问题

3. 事件使用错误引起内存泄露

4. 静态引用引起内存泄露

5. Command引起的内存泄露

6. Style、Xaml引起的内存泄露

7. 弱引用引起的内存泄露

8. MEF等第三方注入库可能引起内存泄露

9. Dispose为何不应该被用来解决托管内存泄露问题——mvvmlight

参考:http://stackoverflow.com/questions/620733/memory-leak-in-c