Bug 31145 - Picker cause memory leak holding entire Page in memory after it popped (WP8 SL only)
Summary: Picker cause memory leak holding entire Page in memory after it popped (WP8 S...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows ()
Version: 1.4.2
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: E.Z. Hart [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2015-06-16 07:11 UTC by Sergey Komisarchik
Modified: 2016-04-10 00:50 UTC (History)
5 users (show)

Tags: ac windows
Is this bug a regression?: ---
Last known good build:


Attachments
Test case (537.27 KB, application/octet-stream)
2015-06-16 07:11 UTC, Sergey Komisarchik
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Sergey Komisarchik 2015-06-16 07:11:55 UTC
Created attachment 11617 [details]
Test case

When page contains Picker then after popping from the NavigationStack or ModalStack page remains in memory.
Here is a complete minimal example:

public class App : Application
{
    public App()
    {
        this.MainPage = new Page1();
    }
}

public class Page1 : ContentPage
{
    public Page1()
    {
        this.Content = new Label() { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
    }

    private WeakReference page2Tracker;

    protected override async void OnAppearing()
    {
        base.OnAppearing();

        if (this.page2Tracker == null)
        {
            var page2 = new Page2();

            this.page2Tracker = new WeakReference(page2, false);

            await Task.Yield();
            await this.Navigation.PushModalAsync(page2);

            this.StartTrackPage2();
        }
    }

    private async void StartTrackPage2()
    {
        while (true)
        {
            ((Label)this.Content).Text = String.Format("Page2 IsAlive = {0}", this.page2Tracker.IsAlive);
            await Task.Delay(1000);
            GC.Collect();
        }
    }
}

public class Page2 : ContentPage
{
    public Page2()
    {
        this.Content = new Picker();   // leak
        // this.Content = new Label(); // no leak
    }

    protected override async void OnAppearing()
    {
        base.OnAppearing();

        await Task.Yield();
        await this.Navigation.PopModalAsync();
    }
}
Comment 1 Chris King 2015-06-26 17:37:46 UTC
Seeing a different bug in Navigation Proxy on Windows Phone 8 in PopModal "var result = list[list.count -1]" invalid index.
Comment 2 Sergey Komisarchik 2015-06-26 18:00:00 UTC
Chris, thanks for the response. I believe you tested with 1.4.3-pre3 version. This bug is tested against 1.4.2 But seems like you faced with this:
https://bugzilla.xamarin.com/show_bug.cgi?id=31366

In 1.4.2 it is not throws but leaking. If you use 1.4.3 then change 
 await Task.Yield()
 to 
 await Task.Delay(1000) before PopModalAsync()

It will still leak.
Comment 3 Jason Smith [MSFT] 2016-04-10 00:50:07 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction.
 
For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards,
Xamarin Forms Team