realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Cyclic reference when using child user control with DataContext binding on the Parent Control

19 Nov 2018, 10:53

Hi,

Noesis C++ 2.1.0f1 - 2.2.0b3
simplified XAML for Window:

<Window x:Class="TrackEditor"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml&quot;
xmlns:d="http://schemas.microsoft.com/expression/blend/2008&quot;
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
mc:Ignorable="d"
Background="#303033" Height="300" Width="900"
Title="Track editor" x:Name="window" IsEnableWindowButtons="True">

<Grid>

<!--UserControl.-->
<WindowCaption Height="30" VerticalAlignment="Top" Background="#01000000" Margin="1,1,30,1" DataContext="{Binding ElementName=window}">
</WindowCaption>

</Grid>
</Window>
if use DataContext = "{Binding ElementName = window}" then when you destroy a window, mView.Reset () does not call WindowCaption () destructor and you cannot destroy Window () because of NumRefCounts > 1

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Cyclic reference when using child user control with DataContext binding on the Parent Control

22 Nov 2018, 17:57

Our implementation has that limitation. Storing a reference to an ancestor in the tree in a DependencyProperty will produce a leak.

There are ways to avoid this by adding some indirection, instead of setting the parent as datacontext, use a viewmodel which can provide the desired information to the children classes. You will have something like this:
<Window x:Class="TrackEditor" ...>
  ...
  <WindowCaption DataContext="{Binding WindowInfo}"
  ...
</Window>
Where WindowInfo is a property of the ViewModel set by your Window as DataContext.

Could that work for you?
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: Cyclic reference when using child user control with DataContext binding on the Parent Control

25 Nov 2018, 14:27

Hi
memory leak, in this situation, is not obvious.
Is it possible to emit a warning in this case?

thank
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Cyclic reference when using child user control with DataContext binding on the Parent Control

25 Nov 2018, 22:04

We are working in a solution that tries to break circular references when elements are disconnected from the view. I think this will cover 99% of the scenarios. Anyway, having the DataContext in the view model, as proposed by sfernandez, is probably a better solution.

Yes, in 2.2.0 you should be getting a log warning. Are you setting up that callback?
 
realesmedia
Topic Author
Posts: 85
Joined: 18 May 2016, 10:26

Re: Cyclic reference when using child user control with DataContext binding on the Parent Control

26 Nov 2018, 12:42

Yes, LogHandler is connected
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Cyclic reference when using child user control with DataContext binding on the Parent Control

26 Nov 2018, 13:51

if (GetAllocatedMemory() > 0)
{
    NS_LOG_WARNING("Memory leaks detected: %d", GetAllocatedMemory() );
}
Please, make sure you are in 2.2.X and that you are receiving messages in your log callback.

Who is online

Users browsing this forum: No registered users and 1 guest