Bug 31255 - Master's page Icon cause memory leak after MasterDetailPage is popped out by holding on page
Summary: Master's page Icon cause memory leak after MasterDetailPage is popped out by ...
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.4.3
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Rui Marinho
URL:
Depends on:
Blocks:
 
Reported: 2015-06-19 13:13 UTC by Sergey Komisarchik
Modified: 2015-08-07 04:51 UTC (History)
4 users (show)

Tags: AC android memoryleak
Is this bug a regression?: ---
Last known good build:


Attachments
Test case (595.83 KB, application/octet-stream)
2015-06-19 13:14 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:
VERIFIED FIXED

Description Sergey Komisarchik 2015-06-19 13:13:34 UTC
Steps to reproduce:
1. Navigate to MasterDetailPage that has Master with Icon property set.
2. Navigate back
3. Result: MasterDetailPage is not garbage collected.

Complete example:

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

public class Page1 : ContentPage
{
    public Page1()
    {
        var stack = new StackLayout() { VerticalOptions = LayoutOptions.Center };

        stack.Children.Add(new Label() { VerticalOptions = LayoutOptions.Center, XAlign = TextAlignment.Center, Text = "Page 1" });

        this.Content = stack;
    }

    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.Delay(1000);
            await this.Navigation.PushModalAsync(page2);

            this.StartTrackPage2();
        }
    }

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

public class Page2 : MasterDetailPage
{
    public Page2()
    {
        this.Master = new Page() { Title = "Master", Icon = "icon.png" };
        this.Detail = new Page() { Title = "Detail" };
    }

    protected override async void OnAppearing()
    {
        base.OnAppearing();
            
        await Task.Delay(1000);
        await this.Navigation.PopModalAsync();
    }
}
Comment 1 Sergey Komisarchik 2015-06-19 13:14:34 UTC
Created attachment 11685 [details]
Test case
Comment 2 Jason Smith [MSFT] 2015-08-05 15:03:51 UTC
Should be fixed in 1.5.0-pre1
Comment 3 Parmendra Kumar 2015-08-07 04:51:17 UTC
I have checked this issue with X.F 1.5.0-pre1 and its working fine at my end.
With X.F 1.5.0-pre1 I am getting: 
Page1. But Page2 IsAlive=False

Hence closing this issue.