-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🚧 Correct ancestor XAML memory leak #4236
🚧 Correct ancestor XAML memory leak #4236
Conversation
…to local/AncestorTheUnloaded
…to dev/AncestorTheUnloaded
Thanks XAML-Knight for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌 |
|
||
treeRoot.Unloaded += (sender, e) => | ||
{ | ||
Assert.AreEqual(grid, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably want to have a value set here that we check is set below after the await SetTestContent as well, otherwise if this doesn't fire then we never know, but we want to make sure it fires, eh?
An issue has been raised (#4246) describing the challenges when running these unit tests via the build script. The workaround for now is to apply the |
If I uncomment the tests, both are failing for me even locally. Though the Test Explorer seems to be very insistent about them still being ignored, had to like completely rebuild and then run in Debug mode. I don't think the Unload event is testing what we expect to occur here. Ideally, locally at least, we want the test to fail without the fix applied and then to pass when we apply the fix. I also noticed that we're missing unregistering the Lines 79 to 85 in 6fd3327
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
// Need to simulate loading the control (and not just rely upon XamlReader.Load) | ||
var frame = new Frame(); | ||
frame.Navigate(treeRoot.GetType()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might need to await this by doing another await App.DispatcherQueue.EnqueueAsync()
Perhaps?
frame.Navigate(treeRoot.GetType()); | |
await App.DispatcherQueue.EnqueueAsync(() => frame.Navigate(treeRoot.GetType())); |
|
||
Assert.IsNull(btn.Parent); | ||
|
||
btn.SetValue(FrameworkElementExtensions.AncestorProperty, new object()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btn.SetValue(FrameworkElementExtensions.AncestorProperty, new object()); | |
await App.DispatcherQueue.EnqueueAsync(() => btn.SetValue(FrameworkElementExtensions.AncestorProperty, new object())); |
|
||
// Need to simulate loading the control (and not just rely upon XamlReader.Load) | ||
var frame = new Frame(); | ||
frame.Navigate(treeRoot.GetType()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frame.Navigate(treeRoot.GetType()); | |
await App.DispatcherQueue.EnqueueAsync(() => frame.Navigate(treeRoot.GetType())); |
var grid = treeRoot.FindChild("OuterGrid") as Grid; | ||
var button = treeRoot.FindChild("InnerButton") as Button; | ||
|
||
button.SetValue(FrameworkElementExtensions.AncestorProperty, new object()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
button.SetValue(FrameworkElementExtensions.AncestorProperty, new object()); | |
await App.DispatcherQueue.EnqueueAsync(() => button.SetValue(FrameworkElementExtensions.AncestorProperty, new object())); |
} | ||
|
||
/// <summary> | ||
/// Attached <see cref="DependencyProperty"/> for retrieving a parent <see cref="object"/> for the <see cref="AncestorProperty"/> | ||
/// </summary> | ||
public static readonly DependencyProperty AncestorProperty = | ||
DependencyProperty.RegisterAttached("Ancestor", typeof(object), typeof(FrameworkElementExtensions), new PropertyMetadata(null)); | ||
DependencyProperty.RegisterAttached("Ancestor", typeof(WeakReference<object>), typeof(FrameworkElementExtensions), new PropertyMetadata(null)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By changing the type here we break using it in XAML as intended. This can be demonstrated with the TokenizingTextBox
as it uses this feature to grab the TokenSpacing
property from its parent.
Closing, superseded by work done in CommunityToolkit/Windows#105 |
Fixes CommunityToolkit/Windows#107
Also #4187
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Steps to Reproduce:
TokenizingTextBox
, for example)What is the new behavior?
The elements should be freed.
PR Checklist
Please check if your PR fulfills the following requirements:
Other information