Skip to main content

Microsoft Silverlight

Memory Leak using StaticResource with ValueConverter in DataGridRSS Feed

(0)

jmorg
jmorg

Member

Member

2 points

10 Posts

Memory Leak using StaticResource with ValueConverter in DataGrid

When using a ValueConverter that makes use of StaticResource to convert value into view format, the parent object never seems to be garbage collected.

Example:

Here I’m using a TerminalStatusConverter which converts “Status” value to image string name for BitmapImage.

             <data:DataGridTemplateColumn Header="Status">               <data:DataGridTemplateColumn.CellTemplate>                  <DataTemplate>                     <Image Source="{Binding Item, Converter={StaticResource TerminalStatusConverter}}" Width="25" Margin="0,10,0,10" Stretch="Uniform"/>                  </DataTemplate>               </data:DataGridTemplateColumn.CellTemplate>

            </data:DataGridTemplateColumn>

 

Using WinDbg I can see that the BitmapImage objects grow and never get garbage collected, even if the datagrid source is pointed to a different ObservableCollection.

 

WinDbg shows that a .Collections.Generic.Dictionary`2+Entry is keeping a reference to the BitmapImage.  What is it?  This can happen with Strings as well.

 0:026> !gcroot 054d0428Note: Roots found on stacks may be false positives. Run "!help gcroot" formore info.Scan Thread 5 OSTHread 2f0Scan Thread 19 OSTHread 198Scan Thread 20 OSTHread a50Scan Thread 21 OSTHread bfcScan Thread 23 OSTHread 560DOMAIN(03DED9E8):HANDLE(Pinned):78812f8:Root:  063f4260(System.Object[])->  053f69c0(System.Collections.Generic.Dictionary`2[[System.IntPtr, mscorlib],[System.Object, mscorlib]])->  054f1b0c(System.Collections.Generic.Dictionary`2+Entry[[System.IntPtr, mscorlib],[System.Object, mscorlib]][])->

  054d0428(System.Windows.Media.Imaging.BitmapImage)->

 Any suggestions?

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities