View Issue Details

IDProjectCategoryView StatusLast Update
0001707NoesisGUIC++ SDKpublic2020-09-24 16:38
Reportersteveh Assigned Tojsantos  
PrioritynormalSeverityfeature 
Status assignedResolutionopen 
Product Version3.0 
Target Version3.0 
Summary0001707: Feature request: Identify and notify the user about cyclic references
Description

Hi guys,

I've recently been looking at cleaning up our shutdown code and I've fixed a few issues where a child holds a ref counted pointer to a parent object in the hierarchy. This ultimately creates a cyclic dependency between the two objects and prevents them from being cleaned up. I've attached 2 examples of code which might do this, the first is setting a DataContext to a parent object, and another is setting the TargetName on a GoToStateAction to a parent object.

It would be extremely helpful to try and detect these cases. Perhaps in debug you could assert if the TargetName or DataContext are trying to be set to a parent object in the hierarchy when you set the pointer. Or perhaps a better way is to try and find these cyclic references in shutdown if we've detected that we've leaked memory. Essentially any further information to help track these issues down would be extremely beneficial!

Cheers.

Steps To Reproduce
  1. Use the attached XAML files in the ApplicationLauncher Noesis sample.
  2. Close the application launcher.
  3. The application will leak and halt if attached in the debugger in Noesis::Shutdown

    if (GetAllocatedMemory() > 0)
    {
        NS_LOG_WARNING("Memory leaks detected: %d bytes", GetAllocatedMemory());
    
        #if defined(NS_DEBUG) && defined(NS_PLATFORM_WINDOWS)
            if (IsDebuggerPresent()) { NS_DEBUG_BREAK; }
        #endif
Attached Files
DataContext.xaml (571 bytes)   
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Name="RootGrid" Background="red" width="100" height="100">
    <!-- This DataContext takes a ref counted pointer to the grid and creates a cyclic depdency -->
    <Border x:Name="Border" DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}}}">
        <TextBlock x:Name="TextBlock" Text="{Binding Name}" VerticalAlignment="Center" HorizontalAlignment="Center" />
    </Border>
</Grid>
DataContext.xaml (571 bytes)   
GoToStateAction.xaml (1,489 bytes)   
<Grid
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
	x:Name="RootGrid" Background="Red">
    <VisualStateManager.VisualStateGroups>
        <VisualStateGroup x:Name="CommonStates">
            <VisualState x:Name="Normal"/>
            <VisualState x:Name="Checked">
                <Storyboard>
                    <ColorAnimation Storyboard.TargetName="RootGrid" Storyboard.TargetProperty="Background.Color" To="Green"/>
                </Storyboard>
            </VisualState>
        </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <Checkbox x:Name="Checkbox" />
    <Border>
        <i:Interaction.Triggers>
            <ei:DataTrigger Binding="{Binding ElementName=Checkbox, Path=IsChecked}" Value="True">
                <!-- This GoToStateAction will create a cyclic dependency as it takes a ref counted pointer to RootGrid -->
                <ei:GoToStateAction StateName="Checked" TargetName="RootGrid" />
            </ei:DataTrigger>
            <ei:DataTrigger Binding="{Binding ElementName=Checkbox, Path=IsChecked}" Value="False">
                <ei:GoToStateAction StateName="Normal" TargetName="RootGrid" />
            </ei:DataTrigger>
        </i:Interaction.Triggers>
    </Border>
</Grid>
GoToStateAction.xaml (1,489 bytes)   
PlatformAny

Relationships

related to 0001706 resolvedsfernandez Memory leak when binding DataContext to parent user control 
related to 0001798 resolvedsfernandez Memory leak when using ContextMenuService.PlacementTarget 

Activities

jsantos

jsantos

2020-06-08 14:04

manager   ~0006428

Last edited: 2020-06-08 14:05

A high-level leak detector with extra information like class name is definitely a good idea. I will try this with your scenario (cyclic dependencies when setting DataContext) to see how useful it is.

Thanks for the suggestion!

Issue History

Date Modified Username Field Change
2020-05-28 11:37 steveh New Issue
2020-05-28 11:37 steveh File Added: DataContext.xaml
2020-05-28 11:37 steveh File Added: GoToStateAction.xaml
2020-05-28 19:08 sfernandez Relationship added related to 0001706
2020-06-08 14:02 jsantos Assigned To => jsantos
2020-06-08 14:02 jsantos Status new => assigned
2020-06-08 14:04 jsantos Note Added: 0006428
2020-06-08 14:04 jsantos Target Version => 3.0
2020-06-08 14:04 jsantos Description Updated
2020-06-08 14:04 jsantos Steps to Reproduce Updated
2020-06-08 14:05 jsantos Note Edited: 0006428
2020-06-08 14:05 jsantos Note Edited: 0006428
2020-09-24 16:38 sfernandez Relationship added related to 0001798