SilverLight - Memory Leak

There is a memory leak issue in current silverlight project. 

It occurs in the search function: the memory usage of corresponding IE process increase about 30MB per search, and never get down.

Here is the way I found the bug and fix it:

1. download Windbg from official site:http://www.windbg.org/ 

when debug .net application, remember to load clr

If it is a 3.5 or lower .NET then you have to load sos by calling ".loadby sos mscorwks". If it is a 4.0 then you have to use ".loadby sos clr".

2. Dump the heap by the command: !dumpheap -stat -type <my project namespace>

So many objects......

3. copy the object data to a text file with named first_seach.txt.

4. tpye command "g" to keep running. And execute the second search function.

5. Break it, and dump the heap again:  !dumpheap -stat -type <my project namespace> 

6. do same operation to get the third heap dump.

7. compare the three txt file, and find the object numbers rule.

8. Luckly, I found my custom data grid object number is the same with the search times. There is the smoking gun.

9. There are dragdrop and contextMenu in this data grid. And both them can cause memory leak: 

http://silverlight.codeplex.com/workitem/6206 

https://silverlight.codeplex.com/workitem/7089 

http://blog.thekieners.com/2010/02/11/simple-weak-event-listener-for-silverlight/ 

So the drag drop and contextMenu are the bullets.

10. follow the fix: open the source code which is already installed on local machine: C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Toolkit\dec11\Source 

11. replace the two bad file: ContextMenu.cs and dragdroptarget.cs. I uploaded both the two files here: http://files.cnblogs.com/crazyghostvon/Sourcecode.zip 

12. Build to release. The test project will build failed if you didn't copy the testing references (C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Toolkit\dec11\Testing\*) to the Binaries folder( C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Toolkit\dec11\Source\Source code\Binaries).

13. Replace the framework references (C:\Program Files (x86)\Microsoft SDKs\Silverlight\v5.0\Toolkit\dec11\Bin)

14. Replace the references of current project, delete it and re-add them all.

15. OK.

 

转载于:https://www.cnblogs.com/crazyghostvon/p/memoryleak.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值