views:

206

answers:

2

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?

A: 

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.

Andrew Garrison
+2  A: 

FYI, to anyone concerned about this issue... MS released a fix for this.

Silverlight 4 Service Release

jamisonLikeCode