Skip to content

Conversation

@pictos
Copy link
Member

@pictos pictos commented Jan 10, 2026

Description of Change

Use WeakReference for the Anchor property.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

Copilot AI review requested due to automatic review settings January 10, 2026 02:41
Copy link
Contributor

Copilot AI left a 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

Copilot AI review requested due to automatic review settings January 10, 2026 03:17
Copy link
Contributor

Copilot AI left a 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.

@pictos pictos enabled auto-merge (squash) January 11, 2026 02:06
Copilot AI review requested due to automatic review settings January 11, 2026 02:06
Copy link
Contributor

Copilot AI left a 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.

@pictos pictos merged commit 15611b7 into CommunityToolkit:main Jan 18, 2026
10 checks passed
@pictos pictos deleted the fix-memory-leak-on-snackbar branch January 18, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] A Snackbar that specifies an Anchor will continue to retain the Anchor inside the Snackbar even after it is dismissed.

2 participants