View Issue Details

IDProjectCategoryView StatusLast Update
0001706NoesisGUIC++ SDKpublic2020-05-28 19:11
ReporterstevehAssigned Tosfernandez 
Status resolvedResolutionwon't fix 
Product Version3.0 
Target Version3.0.1Fixed in Version3.0.1 
Summary0001706: Memory leak when binding DataContext to parent user control
DescriptionHi guys, I'm seeing a memory leak when I bind the DataContext to a parent's user control. This is the sample code I have:

<grid xmlns=""
    x:Name="RootGrid" Background="red" width="100" height="100">
    <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" />

In my case, the root user control is a custom type that I've exposed properties on. I've basically followed the steps on this link to bind to the property on a UserControl:

It seems if I use this pattern it fails to remove the UserControl. Presumably the binding expression creates a circular dependency and is unable to free all resources.
Steps To Reproduce1. Paste the attached document into a Noesis application.
2. Attempt to exit the application.
3. If you're in the debugger, the debugger will break on the following line:

        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; } // here
TagsNo tags attached.


related to 0001707 assignedjsantos Feature request: Identify and notify the user about cyclic references 




2020-05-27 18:06


test.xaml (470 bytes)


2020-05-27 18:11

reporter   ~0006397

Oh I just thought I'd mention, I can fix it by doing the following:

Text="{Binding Path=Name, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Grid}}}"

Essentially ignoring the DataContext and instead setting the RelativeSource directly in the attribute binding. This seems to clean up nicely, it's only if I set the DataContext on a parent object to point to an element further up in the hierarchy that it has issues.


2020-05-27 18:57

manager   ~0006399

This is a known issue in Noesis. Our current implementation of dependency properties like DataContext are keeping a reference to the object set in the property. So setting a parent object (that already keeps a reference to their children) will create a circularity in references that we cannot break leading to leaks.

As you found there are easy ways to workaround this limitation, by using RelativeSource or even simpler ElementName:

Text="{Binding Path=Name, ElementName=RootGrid}"


2020-05-28 02:44

reporter   ~0006405

Cheers, I'm finding a few of these issues around the place now :) I've just hit another issue with triggers and a GoToStateAction with an explicit TargetName of a parent as well. I don't suppose there's a plan to try and track down these circular references is there? Anything which could potentially help to debug these issues would be fantastic! Obviously this is a feature request so quite low priority, especially at the moment as you're dealing with the fallout of the 3.0.0 release :)



2020-05-28 11:09

manager   ~0006408

Last edited: 2020-05-28 11:09

View 2 revisions

This is something I always wanted to improve, not sure exactly how. Could you please create a new ticket about it?



2020-05-28 19:11

manager   ~0006414

Closing this one, ticket 1707 covers this.

Issue History

Date Modified Username Field Change
2020-05-27 18:06 steveh New Issue
2020-05-27 18:06 steveh File Added: test.xaml
2020-05-27 18:11 steveh Note Added: 0006397
2020-05-27 18:57 sfernandez Assigned To => sfernandez
2020-05-27 18:57 sfernandez Status new => feedback
2020-05-27 18:57 sfernandez Note Added: 0006399
2020-05-28 02:44 steveh Note Added: 0006405
2020-05-28 02:44 steveh Status feedback => assigned
2020-05-28 11:09 jsantos Note Added: 0006408
2020-05-28 11:09 jsantos Status assigned => feedback
2020-05-28 11:09 jsantos Note Edited: 0006408 View Revisions
2020-05-28 11:09 jsantos Target Version => 3.0.1
2020-05-28 11:09 jsantos Description Updated View Revisions
2020-05-28 11:09 jsantos Steps to Reproduce Updated View Revisions
2020-05-28 19:08 sfernandez Relationship added related to 0001707
2020-05-28 19:11 sfernandez Status feedback => resolved
2020-05-28 19:11 sfernandez Resolution open => won't fix
2020-05-28 19:11 sfernandez Fixed in Version => 3.0.1
2020-05-28 19:11 sfernandez Note Added: 0006414