Silverlight 4 memory leaks

拥有回忆 提交于 2019-12-19 04:04:29

问题


I have a Silverlight 4 application which has a leaky ViewModel class. I have confirmed this by using WinDbg and the !gcroot command on my ViewModel type. I was unable to pin point the exact cause of the memory leak but have attempted to resolve it by using the following line of code in the corresponding view when it is closed:

HtmlPage.Window.Navigate(new Uri(MyTopLevelUri));   

This forces the app to restart and hence the RootVisual is reinitialised. Now when I use WinDbg I can see that there are no more references holding onto the ViewModel class after the View has closed.

However, when I monitor the memory use of the app (using SysInternals) it continuously increases. Sometimes it may drop slightly but if I keep opening and closing the suspect View I eventually end up with a private byte memory set of over 1,000,000K. Also, even if I add code to force the GC, it never truly recovers all the memory allocated. Should I be worried?

Are there inherent memory leaks with SL4 and the controls? I don't have much faith given the patch that was released recently to fix memory leaks with DataTemplates (version 4.0.60129.0 http://timheuer.com/blog/).


回答1:


It appears that the answer to my original question (are there inherent memory leaks with SL4?) is indeed yes!

http://forums.silverlight.net/forums/t/211504.aspx

https://connect.microsoft.com/VisualStudio/feedback/details/649246/usercontrol-resources-memory-leak-silverlight-4-0-60129-0

The two leaks described in the links above have apparently been fixed in SL5.



来源:https://stackoverflow.com/questions/5091636/silverlight-4-memory-leaks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!