Memory leak when using ContextMenuService.PlacementTarget
Posted: 15 Sep 2017, 06:16
The following XAML causes memory leak. The datacontext object (i.e. the object that provide SomeProperty property) is not released even after UI element is destroyed.
Need to activate the context menu at least once (i.e right-click on the grid) to reproduce the leak.
Memory doesn't leak if I either remove the ContextMenuService.PlacementTarget or the Header="{Binding SomeProperty}".
Code: Select all
<Grid x:Name="MyGrid" Grid.Row="0" Background="WhiteSmoke" ContextMenuService.PlacementTarget="{Binding ElementName=MyGrid}">
<Grid.ContextMenu>
<ContextMenu>
<MenuItem Header="{Binding SomeProperty}"></MenuItem>
</ContextMenu>
</Grid.ContextMenu>
</Grid>
Memory doesn't leak if I either remove the ContextMenuService.PlacementTarget or the Header="{Binding SomeProperty}".