nikobarli
Topic Author
Posts: 180
Joined: 26 Apr 2017, 06:23

Memory leak when using ContextMenuService.PlacementTarget

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.
    <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>
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}".
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Memory leak when using ContextMenuService.PlacementTarget

19 Sep 2017, 13:10

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?
 
nikobarli
Topic Author
Posts: 180
Joined: 26 Apr 2017, 06:23

Re: Memory leak when using ContextMenuService.PlacementTarget

20 Sep 2017, 03:41

The leak is related to PlacementTarget property for sure, I don't think Header binding has anything to do.
I am not sure, but in my environment the leak doesn't happen if I removed the Binding.
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 ?
 
User avatar
jsantos
Site Admin
Posts: 3918
Joined: 20 Jan 2012, 17:18
Contact:

Re: Memory leak when using ContextMenuService.PlacementTarget

22 Sep 2017, 13:01

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 ?
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.

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], Bing [Bot], DHSven, Semrush [Bot] and 4 guests