Skip to content
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

Clear PopupFlyout target on flyout close #15466

Merged
merged 2 commits into from
Apr 23, 2024

Conversation

BAndysc
Copy link
Contributor

@BAndysc BAndysc commented Apr 22, 2024

What does the pull request do?

Flyouts hold a strong reference to target object: #15465 leaking memory. Luckily when the same menu is opened on another target, the memory is released. Still, this is a bug.

What is the current behavior?

What is the updated/expected behavior with this PR?

How was the solution implemented (if it's not obvious)?

The Target in PopupFlyoutBase will be cleared on popup close. I am not sure if this changes any behaviour or not.

Checklist

Breaking changes

Not sure if this changes flyouts behaviour or not.

Obsoletions / Deprecations

Fixed issues

Fixes #15465

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0047560-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@BAndysc BAndysc force-pushed the clear_flyout_target branch from ebfdf49 to 44fa44f Compare April 22, 2024 16:50
@BAndysc BAndysc force-pushed the clear_flyout_target branch from 44fa44f to 344b3ec Compare April 22, 2024 16:50
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0047568-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@robloo
Copy link
Contributor

robloo commented Apr 22, 2024

I don't think you can do this. Target is a valid property and is required for positioning the popup. If you clear it after flyout closes, how will it position correctly the next time it opens?

@BAndysc
Copy link
Contributor Author

BAndysc commented Apr 22, 2024

Keep in mind Target != PlacementTarget. As far as I can see, not sure tho, Target (outside of PopupFlyoutBase) is used only in button:

https://github.com/AvaloniaUI/Avalonia/blob/master/src/Avalonia.Controls/Button.cs#L675-L692

and this usage is still valid, because in the event Target is already set.

usages of Target property

image

@robloo
Copy link
Contributor

robloo commented Apr 22, 2024

So we have a different issue here too. Target is from UWP Flyouts and PlacementTarget is from WPF Popups. We really shouldn't have both and one needs to be obsoleted.

Both properties should really behave the same too. (Havnt looked at code to see how PlacementTarget handles this).

@maxkatz6
Copy link
Member

@robloo it's a bit simpler here. Flyout doesn't have PlacementTarget property. It's an argument of ShowAt(placementTarget) method. And Target property is only set while Flyout is shown, IIRC it's the same in UWP.

@maxkatz6
Copy link
Member

maxkatz6 commented Apr 22, 2024

Double checked, WinUI behaves this way as I expected:

Opening: Microsoft.UI.Xaml.Controls.Button
Opened: Microsoft.UI.Xaml.Controls.Button
Closing: Microsoft.UI.Xaml.Controls.Button
Closed: Microsoft.UI.Xaml.Controls.Button
After Closed: (null) # used a DispatcherQueue

On a Button with ContextFlyout

@maxkatz6 maxkatz6 enabled auto-merge April 23, 2024 09:29
@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.2.999-cibuild0047580-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

@maxkatz6 maxkatz6 added this pull request to the merge queue Apr 23, 2024
Merged via the queue into AvaloniaUI:master with commit 422baaf Apr 23, 2024
10 checks passed
@maxkatz6 maxkatz6 added the backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch label Apr 25, 2024
maxkatz6 pushed a commit that referenced this pull request Apr 25, 2024
* Clear PopupFlyout target on flyout close

* Clear Target after OnClose is called
@maxkatz6 maxkatz6 added backported-11.1.x and removed backport-candidate-11.1.x Consider this PR for backporting to 11.1 branch labels Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Opening a context flyout on a text box leaks memory
4 participants