由于命令未对Silverlight控件进行垃圾回收 [英] Silverlight control not being garbage collected because of command

查看:117
本文介绍了由于命令未对Silverlight控件进行垃圾回收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于绑定了命令,我的控件一直处于活动状态.我如何打破这个参考?这在我的应用程序中导致严重的内存泄漏.该控件位于DataTemplate内部,因此我无法直接访问它.

My control is being kept alive because of command it is bound to. How can I break this reference? This is causing a major memory leak in my application. The control is inside of a DataTemplate so I have no direct access to it.

这是我的ANTS记忆配置文件:

Here is my ANTS memory profile:

到底该如何断开此连接?

How on earth do I break this connection?

推荐答案

尽管我合并了WeakEventListener,但我发现我的问题在于我用来包装图像的控件.我将其连接到DownloadProgressImageOpenedImageFailed事件,但从未解开它们.我的想法是,代码中没有其他东西可以触动BitmapImage对象,因此可以将它们与控件一起进行垃圾回收.事实并非如此. BitmapImage对象是由Microsoft的代码"ManagedPeerTable.PeggedManagedPeersWithRefs"中的静态成员(因此也是GC根目录)引用的.它是如此之深,以至于Google搜索仅返回了五个结果.现在我想将有六个.

Though I incorporated WeakEventListener, I discovered that my problem was with the control I was using to wrap up my images. I was hooking it up to DownloadProgress, ImageOpened, and ImageFailed events and never unhooked them. My thinking was that nothing else in my code was touching the BitmapImage objects so they would be garbage collected with the control. This, it sees, is not the case. The BitmapImage objects were referenced by a static member (and therefore a GC root) deep within Microsoft's code called "ManagedPeerTable.PeggedManagedPeersWithRefs". It was so deep that a Google search returned only five results for it. Now I suppose there will be six.

这篇关于由于命令未对Silverlight控件进行垃圾回收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆