Silverlight DataForm 内存泄漏
一些背景
我注意到设置 DataForm 的 EditTemplate(来自 Silverlight Toolkit)可能会导致 DataForm 不被垃圾收集。因此,DataForm 的父控件也无法进行垃圾收集,从而导致非常严重的内存泄漏。
下面是一些演示这种情况的 XAML。
<toolkit:DataForm HorizontalAlignment="Stretch" Margin="10" VerticalAlignment="Stretch">
<toolkit:DataForm.EditTemplate>
<DataTemplate>
<toolkit:DataField Label="Dummy Binding:">
<TextBox Text="{Binding DummyBinding, Mode=TwoWay}" />
</toolkit:DataField>
</DataTemplate>
</toolkit:DataForm.EditTemplate>
</toolkit:DataForm>
我已在 CodePlex 上提出问题。该问题有一个附件,其中包含 项目 演示了该案例。
所以,我的问题是
还有其他人遇到过这个问题吗?更重要的是,有人知道任何解决方法吗?我怎样才能强制这个DataForm被垃圾收集?
Some Background
I have noticed that setting the EditTemplate of a DataForm (from the Silverlight Toolkit) can cause the DataForm to not be garbage collected. Consequently, the parent control of the DataForm cannot be garbage collected either, causing a very significant memory leak.
Here's some XAML which demonstrates the case.
<toolkit:DataForm HorizontalAlignment="Stretch" Margin="10" VerticalAlignment="Stretch">
<toolkit:DataForm.EditTemplate>
<DataTemplate>
<toolkit:DataField Label="Dummy Binding:">
<TextBox Text="{Binding DummyBinding, Mode=TwoWay}" />
</toolkit:DataField>
</DataTemplate>
</toolkit:DataForm.EditTemplate>
</toolkit:DataForm>
I have opened an issue on CodePlex. The isssue has an attachment which has a project which desmonstrates the case.
So, My Question Is
Has anyone else encountered this issue? More importantly, does anyone know of any workarounds? How can I force this DataForm to be garbage collected?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅供参考,对于任何关心这个问题的人...微软发布了一个修复程序。
Silverlight 4 服务版本
FYI, to anyone concerned about this issue... MS released a fix for this.
Silverlight 4 Service Release
事实证明,这个问题并不是 DataForm 控件特有的,它实际上是 Silverlight 4 运行时的问题。所有使用 DataTemplate 的内置控件和用户控件都存在此问题,此线程。 Tim Heuer(Silverlight 项目经理)在该线程中做出了响应,并提出了一种可能的解决方法,结果好坏参半。他确实提到他们已经有一个修复程序进入测试,所以希望更新应该很快发布。
It turns out that this issue is not specific to the DataForm control, and that it is actually a problem with the Silverlight 4 runtime. All built-in controls and user controls that use a DataTemplate have this issue as discussed in greater detail in this thread. Tim Heuer (the Silverlight Program Manager) is responsive on the thread and proposes a possible workaround with mixed results. He does mention that they already have a fix entered into testing, so hopefully an update should be released relatively soon.