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

[ios/catalyst] fix memory leaks in *Cell #22067

Merged
merged 8 commits into from
May 17, 2024

Commits on May 16, 2024

  1. [ios/catalyst] fix memory leaks in *Cell

    Context: https://github.com/AdamEssenmacher/MemoryToolkit.Maui/tree/main/samples
    
    Retesting this sample with the `ListView` leak fixed, I noticed the
    sample reports 0 leaks! Unfortunately, it still displayed memory growing
    over time...
    
    Taking a `.gcdump` snapshot, I noticed a cycle:
    
    * `ViewCellRenderer.ViewTableCell` -> `ViewCell _viewCell` -> `ViewCellRenderer` -> `ViewTableCell`
    
    I was able to write a test that reproduces the leak, and I extended it
    for every type of `*Cell` like `TextCell`, `ImageCell`, `SwitchCell`, etc.
    
    The fixes are:
    
    * `ViewTableCell` now uses a `WeakReference<ViewCell> _viewCell`
    
    * `CellTableViewCell` now uses a `WeakReference<Cell> _cell`
    
    * `CellTableViewCell` now uses a `WeakEventManager` for `PropertyChanged`,
      as the `*Renderer` subscribes to this event.
    
    Note that I changed `PropertyChanged` to an event, which is an API
    change. (I can revisit this if needed)
    jonathanpeppers authored and PureWeen committed May 16, 2024
    Configuration menu
    Copy the full SHA
    f349108 View commit details
    Browse the repository at this point in the history
  2. Fixed all public API changes

    jonathanpeppers authored and PureWeen committed May 16, 2024
    Configuration menu
    Copy the full SHA
    6c1cb88 View commit details
    Browse the repository at this point in the history
  3. Better null checking

    One test was crashing (even on rerun), so maybe this will fix
    jonathanpeppers authored and PureWeen committed May 16, 2024
    Configuration menu
    Copy the full SHA
    bff1848 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    ee996a6 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    6afe10b View commit details
    Browse the repository at this point in the history
  6. - cleanup

    PureWeen committed May 16, 2024
    Configuration menu
    Copy the full SHA
    d9e0f64 View commit details
    Browse the repository at this point in the history
  7. Update CellTableViewCell.cs

    PureWeen committed May 16, 2024
    Configuration menu
    Copy the full SHA
    12c1161 View commit details
    Browse the repository at this point in the history
  8. - add additional unshipped

    PureWeen committed May 16, 2024
    Configuration menu
    Copy the full SHA
    d518c87 View commit details
    Browse the repository at this point in the history