rotorgames / Rg.Plugins.Popup

Xamarin Forms popup plugin
MIT License
1.15k stars 336 forks source link

Memory leak when pushing and poping a page many times #745

Open fpuente70 opened 1 year ago

fpuente70 commented 1 year ago

šŸ› Bug Report

There seems to be a memory leak in the push/pop process which can be significative after many iterations, especially on IOS.

Expected behavior

whatever is done during push/pop process should release the memory used for it to avoid memory leaks

Reproduction steps

        long memoryBefore = GC.GetTotalMemory(true);
        MyPopupPage popup = new MyPopupPage();
        for (int i = 0; i < 1000; i++)
        {
            await PopupNavigation.Instance.PushAsync(popup);
            await PopupNavigation.Instance.RemovePageAsync(popup);
        }
        GC.Collect();
        long memoryAfter = GC.GetTotalMemory(true);
        Console.WriteLine("{0:D}", memoryAfter - memoryBefore);

doing this with the base PopupPage or an empty derived class will result in no significative memory leak. However, when you start to put things on the XAML like grids, lists, labels, images, etc it starts to slowly leak memory, proportionally with the amount of elements displayed on the popup page. The amount of memory leaked seems to be more on IOS than on Android, but they both show leaks.

Configuration

Version: 1.x version 1.2.0.223 Platform:

LennoxP90 commented 9 months ago

I may have fixed this from #762