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

推荐订阅源

H
Heimdal Security Blog
A
Arctic Wolf
K
Kaspersky official blog
V
Vulnerabilities – Threatpost
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog
L
LINUX DO - 热门话题
MongoDB | Blog
MongoDB | Blog
T
Threat Research - Cisco Blogs
D
Docker
爱范儿
爱范儿
T
Tenable Blog
C
Check Point Blog
B
Blog
C
Cisco Blogs
Vercel News
Vercel News
The Cloudflare Blog
T
Threatpost
NISL@THU
NISL@THU
T
Tor Project blog
V2EX - 技术
V2EX - 技术
P
Palo Alto Networks Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
T
Tailwind CSS Blog
G
GRAHAM CLULEY
P
Privacy & Cybersecurity Law Blog
SecWiki News
SecWiki News
博客园 - 司徒正美
S
Security @ Cisco Blogs
GbyAI
GbyAI
S
Secure Thoughts
Microsoft Security Blog
Microsoft Security Blog
The Register - Security
The Register - Security
Recorded Future
Recorded Future
Cloudbric
Cloudbric
Webroot Blog
Webroot Blog
N
News and Events Feed by Topic
Y
Y Combinator Blog
博客园_首页
T
Troy Hunt's Blog
The Hacker News
The Hacker News
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
U
Unit 42
AWS News Blog
AWS News Blog
PCI Perspectives
PCI Perspectives
V
Visual Studio Blog
博客园 - 聂微东
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell

博客园 - 思无邪

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