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

ItemsRepeater leak #644

Open
Mozart-UA opened this issue Jan 28, 2025 · 0 comments
Open

ItemsRepeater leak #644

Mozart-UA opened this issue Jan 28, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@Mozart-UA
Copy link

Issue Description:

It seems that the ItemsRepeater component is causing memory leaks. After some investigation, I have determined that the leaks are due to lingering references to EventHandler in the OnLayoutChanged method.

Desktop/Platform:

  • OS: Windows (10 / 11)
  • FluentAvalonia Version (2.1.0 / 2.2.0)
  • Avalonia Version 11.2.3

Steps to Reproduce:

  1. Create a UserControl.
  2. Place an empty ItemsRepeater on it, data binding is not necessary.
  3. Create a window and display this UserControl in the new window as content.
  4. Close the window.

LeakTestItemsRepeater.zip

Expected Behavior:
Closing the window should release all references to objects and remove the window from memory.

Actual Behavior:
References to the Window are held by the UserControl, references to the UserControl are held by ItemsRepeater, and references to ItemsRepeater are held by Layout. This causes memory leaks and prevents garbage collection. The specific event handlers involved are:

  • Layout.MeasureInvalidated -/+ InvalidateMeasureForLayout;
  • Layout.ArrangeInvalidated -/+ InvalidateArrangeForLayout;

Additional context:
See attached sample project. Each time the "Yes Leak" button is pressed, objects will be created, but will never be deleted from memory.
In contrast, clicking the "No Leak" button creates objects, and closing the window marks objects for deletion.

@Mozart-UA Mozart-UA added the bug Something isn't working label Jan 28, 2025
Mozart-UA added a commit to Mozart-UA/FluentAvalonia that referenced this issue Jan 28, 2025
Add `WeakTypedEventHandler` for binding events with weak references.
Added weak event handlers to `ItemsRepeater` for `InvalidateMeasureForLayout` and `InvalidateArrangeForLayout`.
Fixed logical errors in check conditions.
Improve error message for `DataSource`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant