Skip to content

Memory leaks due to Garbage Collector not disposing controls with nested external controls #13834

Closed as not planned
@dfernandezramos

Description

@dfernandezramos

Describe the bug

Garbage Collector is not disposing Avalonia controls containing nested controls coming from another UserControl classes and turned invisible resulting on memory leaks.

To Reproduce

Steps to reproduce the behavior:

  1. Run the AvaloniaLeakSample application [email protected]:LongoMatch/AvaloniaLeakSample.git
  2. Click on the 'Move to view 2' button
  3. Click on the 'BACK' button
  4. Repeat steps 2 & 3 several times until GC disposes unused objects

Expected behavior

Mind the application output. View2 is not being destroyed. You should see "There is no leak on view 1" and "There is no leak on view 2" messages several times but only "There is no leak on view 1" is being displayed.

Screenshots

Screenshot 2023-12-05 at 10 39 00
Screenshot 2023-12-05 at 10 41 23

Environment

  • OS: Tested on macOS Sonoma and Windows 10
  • Avalonia-Version: 11.0.5

Additional context

Important information:

  • Leak on "View 2" happens when using <sample:NestedControl1> (which just contains a button) AND setting NestedControl.IsVisible = false; on the code behind at the OnInitialized () method.
  • Leak also happens when using <sample:NestedControl1> AND setting its IsVisible="False" property on the XAML file.
  • Not setting <sample:NestedControl1> as invisible or if we just use a <Button> instead does not leak even if we set that button as not visible on the code behind at the OnInitialized () method or the XAML file.
  • It seems it just happens with the button control. Changing <Button> for <Rectangle> or other controls in the nested control class does not produce the leak

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions