-
Notifications
You must be signed in to change notification settings - Fork 472
Fix memory leak on snackbar #3034
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
Fix memory leak on snackbar #3034
Conversation
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.
Pull request overview
This pull request fixes a memory leak in the Snackbar component by using a WeakReference to store the Anchor property, preventing the Snackbar from keeping strong references to UI elements that should be garbage collected.
Changes:
- Added a new WeakReferenceExtensions class with a GetTargetOrDefault extension method for convenient WeakReference handling
- Modified the Anchor property in Snackbar to use WeakReference for storage instead of directly storing the IView reference
- Minor formatting fix to a documentation comment
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/CommunityToolkit.Maui/Extensions/WeakReferenceExtensions.cs | New extension method to simplify retrieving WeakReference targets |
| src/CommunityToolkit.Maui/Alerts/Snackbar/Snackbar.shared.cs | Modified Anchor property to use WeakReference backing field; minor comment formatting correction |
Co-authored-by: Copilot <[email protected]>
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.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
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.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Description of Change
Use WeakReference for the Anchor property.
Linked Issues
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information