Skip to content

CollectionView is not currently being Garbage Collected #20710

Description

@marco-skizza

Description

Hi

With the following Xaml on a page, the page doesn't get garbage collected when navigating back:

        <CollectionView ItemsSource="{Binding Items}">
            <CollectionView.ItemTemplate >
                <DataTemplate>
                    <Grid>

                        <Label Text="Test" />

                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

Steps to Reproduce

  • Run the project
  • Click Button and go back again multiple times
  • Observe that ~MyPage() never gets called

Link to public reproduction project repository

https://github.com/marco-skizza/MauiCollectionView

Version with bug

8.0.7 SR2

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, I was not able test on other platforms

Affected platform versions

iPadOS 17.3.1 on iPad mini 6

Did you find any workaround?

No

Relevant log output

No response

Activity

  1. added
    t/bug
    on Feb 19, 2024
  2. added
    legacy-area-perf
    area-controls-collectionview
    on Feb 20, 2024
  3. added
    perf/memory-leak 💦
    on Feb 20, 2024
  4. added this to the Backlog milestone on Feb 20, 2024
  5. changed the title [-]CollectionView with ItemsSource Binding is not currently being Garbage Collected[/-] [+]CollectionView is not currently being Garbage Collected[/+] on Feb 24, 2024
  6. marco-skizza commented on Feb 24, 2024

    @marco-skizza
    Author

    As I observed, the CollectionView also leaks when setting the ItemsSource in the code behind directly.
    The CollectionView seems to leak as long as the ItemTemplate is not "empty", e.g. as long as it contains some "real" elements like the Label in my sample.

  7. modified the milestones: Backlog, .NET 8 SR4 on Mar 12, 2024
  8. jonathanpeppers commented on Mar 14, 2024

    @jonathanpeppers
    Member
  9. marco-skizza commented on Mar 15, 2024

    @marco-skizza
    Author

    Hi @jonathanpeppers

    The GC.Collect() is in the MainPage.xaml.cs after navigating back again from the page with the CollectionView:

    https://github.com/marco-skizza/MauiCollectionView/blob/756c7e874465aee645a7ebe59bffa3555ee68bfa/MauiCollectionView/MainPage.xaml.cs#L15-L21

    But tell me if I should add some more of those calls to the OnAppearing() to make it more deterministic...

    P.S.:
    With the current code I have to navigate forth and back several times to see the effect of GC.Collect().

    P.P.S.:
    I tested this with the Debug build. But so far, this approach was good enough for me.

  10. 22 remaining items

  11. brentpbc commented on Apr 15, 2024

    @brentpbc

    @jonathanpeppers Thanks for looking at this :)

  12. added a commit that references this issue on May 6, 2024
  13. added
    perf/general
    and removed
    legacy-area-perf
    on May 10, 2024
  14. locked and limited conversation to collaborators on Jun 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area-controls-collectionviewfixed-in-8.0.20fixed-in-8.0.40fixed-in-9.0.0-preview.3.10457fixed-in-9.0.0-preview.5.24307.10perf/generalperf/memory-leak 💦platform/ioss/needs-attentiont/bug

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions