roubachof/Sharpnado.CollectionView

Memory Leak in CollectionView

Closed this issue · 4 comments

Describe the bug
When I have the sho:CollectionView in a detail page and I navigate to it and back (repeat). The page count of the detail page is increasing. When I remove the sho:CollectionView from the page the detail page gets garbage collected as expected.

I haven't been able to drill it down into the control but I managed to reproduce it with a minimal XAML without events:

To Reproduce

                        <sho:CollectionView 
                                CollectionLayout="Horizontal"
                                ItemsSource="{Binding MediaFiles}"
                                SnapStyle="Start">

                            <sho:CollectionView.ItemTemplate>
                                <DataTemplate  x:DataType="models:Media">
                                    <ViewCell>
                                        <Label Text="{Binding Url}"/>
                                    </ViewCell>
                                </DataTemplate>
                            </sho:CollectionView.ItemTemplate>
                        </sho:CollectionView>
                            

Platform:

  • OS: iOS (did not test Android)
  • Device: iPhone7/iPhoneSimulator
  • Xamarin.Forms: latest stable and development branch

=== Xamarin.Profiler ===

Version: 1.6.15.68
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 13.2.1 (19586)
Build 13C100

Version: 12.0.0.3 (Visual Studio Enterprise)
Commit: xamarin-android/d16-11/f0e3c2d
Android SDK: /Users/developer/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
8.0 (API level 26)
8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 30.0.5
SDK Build Tools Version: 31.0.0

=== Xamarin.iOS ===

Version: 15.4.0.0 (Visual Studio Enterprise)
Hash: 8fc41ae82
Branch: xcode13.2
Build date: 2021-12-09 01:07:56-0500

=== Operating System ===

Mac OS X 12.2.0

I tried to add a WeakReference that was maybe(?) missing.

I've tried the latest code but it still has a memory leak somewhere. The same issue, going to GridPage and back increases the number of live GridPages.
I haven't managed to track it down yet since I'm a bit short in time.

The linked PR will fix the issue for MAUI only.