问题描述
我有一个Silverlight 4应用程序,该应用程序有一个泄漏的ViewModel类.我已经通过在ViewModel类型上使用WinDbg和!gcroot命令来确认这一点.我无法查明内存泄漏的确切原因,但是尝试通过在相应的视图关闭时使用以下代码行来解决该问题:
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));
这将强制应用程序重新启动,因此RootVisual被重新初始化.现在,当我使用WinDbg时,可以看到在视图关闭后不再有引用保留在ViewModel类上.
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.
但是,当我监视应用程序的内存使用情况(使用SysInternals)时,它不断增加.有时它可能会稍微下降,但是如果我继续打开和关闭可疑视图,我最终将得到一个超过1,000,000K的专用字节存储集.同样,即使我添加了强制执行GC的代码,它也无法真正恢复分配的所有内存.我应该担心吗?
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?
SL4和控件是否存在固有的内存泄漏?对于最近发布的用于修复DataTemplates(版本4.0.60129.0 http://timheuer.com/blog/).
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/).
推荐答案
看来,我原来的问题的答案(SL4是否存在固有的内存泄漏?)的确是肯定的!
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
上面链接中描述的两个泄漏显然已在SL5中修复.
The two leaks described in the links above have apparently been fixed in SL5.
这篇关于Silverlight 4内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!