Memory leak when using ContextMenuService.PlacementTarget
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}".
-
-
sfernandez
Site Admin
- Posts: 2738
- Joined:
Re: Memory leak when using ContextMenuService.PlacementTarget
The leak is related to PlacementTarget property for sure, I don't think Header binding has anything to do.
Could you please report it in our bugtracker?
Could you please report it in our bugtracker?
Re: Memory leak when using ContextMenuService.PlacementTarget
I am not sure, but in my environment the leak doesn't happen if I removed the Binding.The leak is related to PlacementTarget property for sure, I don't think Header binding has anything to do.
I filed the issue: #001153
BTW, is there any diagnostic techniques to detect memory leaks when it happens ? Maybe an API to query for undestroyed BaseComponents after NoesisGUI::Shutdown is called ?
Re: Memory leak when using ContextMenuService.PlacementTarget
Debug and Profile versions of NoesisGUI (we are not distributing these binaries for now, only clients with access to source code can generate them) include a memory leak detection mechanism. But we want to move it out of core and have it in the application framework we are going to open source soon.BTW, is there any diagnostic techniques to detect memory leaks when it happens ? Maybe an API to query for undestroyed BaseComponents after NoesisGUI::Shutdown is called ?
For now, the best way is implementing a custom allocator (that you can pass at Init time) and count allocations minus deallocations to detect leaks.
Who is online
Users browsing this forum: Ahrefs [Bot] and 2 guests