Exemplo n.º 1
0
        public Bugzilla45722Xaml0()
        {
#if APP
            InitializeComponent();

            Model = new ObservableCollection <_45722Group>();

            RefreshModel();

            IsGroupingEnabled = true;
            BindingContext    = this;

            RefreshButton.Clicked += (sender, args) => { RefreshModel(); };

            GCButton.Clicked += (sender, args) =>
            {
                GarbageCollectionHelper.Collect();
            };

            MessagingCenter.Subscribe <_45722Label>(this, _45722Label.CountMessage, sender =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    CurrentCount.Text = _45722Label.Count.ToString();

                    // GroupHeader label + (3 items per group * 2 labels per item) = 7
                    Result.Text = (_45722Label.Count - (ItemCount * 7)) <= 0 ? Success : Running;
                });
            });
#endif
        }
            async void Button_Clicked(object sender, EventArgs e)
            {
                Debug.WriteLine(">>>>>>>> Invoking Garbage Collector");
                GarbageCollectionHelper.Collect();

                await Navigation.PushAsync(new BugPage());
            }
Exemplo n.º 3
0
        protected override void Init()
        {
            var result = new Label
            {
                FontSize = 16,
                Text     = "Click 'Push page' twice"
            };

            var list = new List <WeakReference>();

            var checkButton = new Button
            {
                Text      = "Check Result",
                IsEnabled = false,
                Command   = new Command(() =>
                {
                    if (list.Count < 2)
                    {
                        result.Text = "Click 'Push page' again";
                        return;
                    }

                    GarbageCollectionHelper.Collect();
                    result.Text = list[list.Count - 2].IsAlive ? "Failed" : "Success";
                })
            };

            Content = new StackLayout
            {
                Children =
                {
                    result,
                    new Button
                    {
                        Text    = "Push page",
                        Command = new Command(async() => {
                            var page = new LeakPage();
                            var wref = new WeakReference(page);

                            await Navigation.PushAsync(page);
                            await page.Navigation.PopAsync();

                            GarbageCollectionHelper.Collect();

                            list.Add(wref);
                            if (list.Count > 1)
                            {
                                checkButton.IsEnabled = true;
                                result.Text           = "You can check result";
                            }
                            else
                            {
                                result.Text = "Again";
                            }
                        })
                    },
                    checkButton
                }
            };
        }
 void OnAllEventsDetached(object sender, EventArgs args)
 {
     AttachedStateEffects.Clear();
     AttachedStateEffects.AllEventsDetached -= OnAllEventsDetached;
     GarbageCollectionHelper.Collect();
     AllEffectsHaveDetached.Text = "Success";
 }
Exemplo n.º 5
0
        protected override void Init()
        {
            var label = new Label()
            {
                Text = "Testing..."
            };

            var goButton = new Button {
                Text = "Go", AutomationId = "Go"
            };

            goButton.Clicked += (sender, args) => Application.Current.MainPage = new _44166MDP();

            var gcButton = new Button {
                Text = "GC", AutomationId = "GC"
            };

            gcButton.Clicked += (sender, args) =>
            {
                GarbageCollectionHelper.Collect();

                if (_44166MDP.Counter > 0)
                {
                    Debug.WriteLine($">>>>>>>> Post-GC, {_44166MDP.Counter} {nameof(_44166MDP)} allocated");
                }

                if (_44166Master.Counter > 0)
                {
                    Debug.WriteLine($">>>>>>>> Post-GC, {_44166Master.Counter} {nameof(_44166Master)} allocated");
                }

                if (_44166Detail.Counter > 0)
                {
                    Debug.WriteLine($">>>>>>>> Post-GC, {_44166Detail.Counter} {nameof(_44166Detail)} allocated");
                }

                if (_44166NavContent.Counter > 0)
                {
                    Debug.WriteLine($">>>>>>>> Post-GC, {_44166NavContent.Counter} {nameof(_44166NavContent)} allocated");
                }

                int success = 0;

                //some reason there's always 1 instance around i don't know why yet, if we were leaking it should be 8 here
                if (Device.RuntimePlatform == Device.macOS)
                {
                    success = 4;
                }

                if (_44166NavContent.Counter + _44166Detail.Counter + _44166Master.Counter + _44166MDP.Counter == success)
                {
                    label.Text = "Success";
                }
            };

            Content = new StackLayout
            {
                Children = { label, goButton, gcButton }
            };
        }
        public Page2()
        {
            GarbageCollectionHelper.Collect();

            Title = "Page2";
            System.Diagnostics.Debug.WriteLine("Constructor");
            NavigationPage.SetBackButtonTitle(this, "Custom");
        }
        async void OnAllEventsAttached(object sender, EventArgs args)
        {
            AttachedStateEffects.AllEventsAttached -= OnAllEventsAttached;
            // needed otherwise UWP crashes
            await Task.Delay(100);

            await Navigation.PopAsync();

            GarbageCollectionHelper.Collect();
        }
Exemplo n.º 8
0
        static Page CreateWeakReferencedPage()
        {
            GarbageCollectionHelper.Collect();

            var result = CreatePage();

            s_pageRefs.Add(new WeakReference(result));

            return(result);
        }
Exemplo n.º 9
0
        async void StartTrackPage2()
        {
            while (true)
            {
                ((Label)((StackLayout)Content).Children [0]).Text =
                    string.Format("Page1. But Page2 IsAlive = {0}", _page2Tracker.IsAlive);
                await Task.Delay(1000);

                GarbageCollectionHelper.Collect();
            }
        }
Exemplo n.º 10
0
        public void Issue4973Test()
        {
            RunningApp.Tap(q => q.Text("Tab5"));

            RunningApp.WaitForElement(q => q.Text("Test"));

            GarbageCollectionHelper.Collect();

            RunningApp.Tap(q => q.Text("Tab1"));

            RunningApp.Tap(q => q.Text("Tab2"));
        }
Exemplo n.º 11
0
        protected override void Init()
        {
            Button createPage, sendMessage, doGC;

            Label instanceCount = new Label();
            Label messageCount  = new Label();

            instanceCount.Text = $"Instances: {_45926SecondPage.InstanceCounter.ToString()}";
            messageCount.Text  = $"Messages: {_45926SecondPage.MessageCounter.ToString()}";

            var content = new ContentPage
            {
                Title   = "Test",
                Content = new StackLayout
                {
                    VerticalOptions = LayoutOptions.Center,
                    Children        =
                    {
                        (createPage  = new Button {
                            Text     = "New Page"
                        }),
                        (sendMessage = new Button {
                            Text     = "Send Message"
                        }),
                        (doGC        = new Button {
                            Text     = "Do GC"
                        }),
                        instanceCount, messageCount
                    }
                }
            };

            createPage.Clicked += (s, e) =>
            {
                PushAsync(new _45926IntermediatePage());
                PushAsync(new _45926SecondPage());
            };

            sendMessage.Clicked += (s, e) =>
            {
                MessagingCenter.Send(this, "Test");
            };

            doGC.Clicked += (sender, e) =>
            {
                GarbageCollectionHelper.Collect();
                instanceCount.Text = $"Instances: {_45926SecondPage.InstanceCounter.ToString()}";
                messageCount.Text  = $"Messages: {_45926SecondPage.MessageCounter.ToString()}";
            };

            PushAsync(content);
        }
Exemplo n.º 12
0
        static Page CreateWeakReferencedPage()
        {
            GarbageCollectionHelper.Collect();
            var result = CreatePage();

            s_pageRefs.Add(new WeakReference(result));

            // Add a second unreferenced page to prove that the problem only exists
            // when pages are actually navigated to/from
            s_pageRefs.Add(new WeakReference(CreatePage()));
            GarbageCollectionHelper.Collect();
            return(result);
        }
        async void StartTrackPage2()
        {
            var n = 0;

            while (_page2Tracker.IsAlive)
            {
                _resultLabel.Text = $"Page2 IsAlive = {_page2Tracker.IsAlive} ({n++})";
                await Task.Delay(1000);

                GarbageCollectionHelper.Collect();
            }

            _resultLabel.Text = $"Page2 IsAlive = {_page2Tracker.IsAlive}";
        }
Exemplo n.º 14
0
        public LandingPage32206()
        {
            Label = new Label
            {
                Text = "Counter: " + Counter,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center
            };

            Content = new StackLayout
            {
                Orientation       = StackOrientation.Vertical,
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.Center,
                Spacing           = 15,
                Children          =
                {
                    new Label
                    {
                        Text = "Click Push to show a ListView. When you hit the Back button, Counter will show the number of pages that have not been finalized yet."
                               + " If you click GC, the counter should be 0."
                    },
                    Label,
                    new Button
                    {
                        Text         = "GC",
                        AutomationId = "GC",
                        Command      = new Command(o =>
                        {
                            GarbageCollectionHelper.Collect();
                            Label.Text = "Counter: " + Counter;
                        })
                    },
                    new Button
                    {
                        Text         = "Push",
                        AutomationId = "Push",
                        Command      = new Command(async o =>
                        {
                            await Navigation.PushAsync(new ContentPage32206());
                        })
                    }
                }
            };
        }
Exemplo n.º 15
0
        async void StartTrackPage2()
        {
            var watch = new Stopwatch();

            watch.Start();

            // We'll let this run until the references are dead or timeout has passed
            while (_page2Tracker.IsAlive && _tabTracker.IsAlive && watch.ElapsedMilliseconds < Timeout)
            {
                await Task.Delay(1000);

                GarbageCollectionHelper.Collect();
            }

            watch.Stop();

            _result.Text = _page2Tracker.IsAlive || _tabTracker.IsAlive ? Fail : Success;
        }
        protected override void Init()
        {
            AllEffectsHaveDetached = new Label()
            {
                AutomationId = "AllEventsHaveDetached",
                Text         = "If this text doesn't change then all effects haven't detached"
            };

            var newPage = new ContentPage
            {
                Content =
                    new StackLayout()
                {
                    Children =
                    {
                        new Button
                        {
                            Text    = "Show New ListView",
                            Command = new Command(async o => await Navigation.PushAsync(new ListPage())),
                        },

                        new Button
                        {
                            Text    = "Garbage Collection Things",
                            Command = new Command(() =>
                            {
                                GarbageCollectionHelper.Collect();
                                AttachedStateEffects.Clear();
                            }),
                        },
                        AllEffectsHaveDetached
                    }
                },
                AutomationId = "ContentPage"
            };

            AttachedStateEffects.AllEventsAttached += OnAllEventsAttached;
            AttachedStateEffects.AllEventsDetached += OnAllEventsDetached;

            var listPage = new ListPage();

            Navigation.PushAsync(listPage);
            Navigation.InsertPageBefore(newPage, listPage);
        }
Exemplo n.º 17
0
        protected override void Init()
        {
            var viewModel = new ObservableCollection <_55365Item>
            {
                new _55365Item {
                    Subject = 65
                }
            };

            viewModel.CollectionChanged += OnCollectionChanged;

            _itemsPanel.BindingContext = viewModel;

            foreach (_55365Item item in viewModel)
            {
                _itemTemplate.SetValue(BindingContextProperty, item);
                var view = (View)_itemTemplate.CreateContent();
                _itemsPanel.Children.Add(view);
            }

            var clearButton = new Button {
                Text = "Clear", Command = new Command(o => viewModel.Clear())
            };

            _layout.Children.Add(clearButton);

            var collectButton = new Button
            {
                Text    = "Garbage",
                Command = new Command(o =>
                {
                    GarbageCollectionHelper.Collect();
                    _layout.Children.Add(new Label {
                        Text = "Success"
                    });
                })
            };

            _layout.Children.Add(collectButton);
            _layout.Children.Add(_itemsPanel);

            Content = _layout;
        }
Exemplo n.º 18
0
        protected override async void Init()
        {
            Flyout = new ContentPage {
                Title = "Title"
            };
            Detail = new NavigationPage(new Issue9419Page());

            await Task.Delay(TimeSpan.FromSeconds(3));

            Detail = new NavigationPage(new Issue9419Page());

            await Task.Delay(TimeSpan.FromSeconds(3));

            GarbageCollectionHelper.Collect();

            Detail = new NavigationPage(new ContentPage {
                Content = new Label {
                    Text = OkResult
                }
            });
        }
Exemplo n.º 19
0
 void GCbutton_Clicked(object sender, EventArgs e)
 {
     System.Diagnostics.Debug.WriteLine(">>>>>>>> Running Garbage Collection");
     GarbageCollectionHelper.Collect();
     System.Diagnostics.Debug.WriteLine($">>>>>>>> GC.GetTotalMemory = {GC.GetTotalMemory(true):n0}");
 }
Exemplo n.º 20
0
        protected override void Init()
        {
            _currentLabelCount = new Label();
            _statusLabel       = new Label {
                Text = Running
            };

            MessagingCenter.Subscribe <_45722Label>(this, _45722Label.CountMessage, sender =>
            {
                Device.BeginInvokeOnMainThread(() =>
                {
                    _currentLabelCount.Text = _45722Label.Count.ToString();
                    _statusLabel.Text       = _45722Label.Count - ItemCount <= 0 ? Success : Running;
                });
            });

            var lv = new ListView(ListViewCachingStrategy.RetainElement);

            var items = new ObservableCollection <_45722Model>();

            foreach (var item in CreateItems())
            {
                items.Add(item);
            }

            var dt = new DataTemplate(() =>
            {
                var layout = new Grid();

                var label = new _45722Label();
                label.SetBinding(Label.TextProperty, new Binding("Text"));

                var bt = new Button {
                    Text = "Go"
                };
                bt.SetBinding(Button.CommandProperty, new Binding("Command"));

                var en = new Entry {
                    Text = "entry"
                };

                layout.Children.Add(bt);
                layout.Children.Add(en);
                layout.Children.Add(label);

                Grid.SetRow(bt, 1);
                Grid.SetRow(en, 2);

                return(new ViewCell {
                    View = layout
                });
            });

            lv.ItemsSource  = items;
            lv.ItemTemplate = dt;

            var button = new Button {
                Text = Update
            };

            button.Clicked += (sender, args) =>
            {
                items.Clear();
                foreach (var item in CreateItems())
                {
                    items.Add(item);
                }
            };

            var collect = new Button()
            {
                Text = Collect
            };

            collect.Clicked += (sender, args) =>
            {
                GarbageCollectionHelper.Collect();
            };

            Title   = "Bugzilla 45722";
            Content = new StackLayout
            {
                Padding  = new Thickness(0, 20, 0, 0),
                Children = { _currentLabelCount, _statusLabel, button, collect, lv }
            };
        }
        protected override void Init()
        {
            if (Application.Current.Resources == null)
            {
                Application.Current.Resources = new ResourceDictionary();
            }

            if (!Application.Current.Resources.ContainsKey("SomeSmallImage"))
            {
                ImageSource smallImage;
                switch (Device.RuntimePlatform)
                {
                default:
                    smallImage = "coffee.png";
                    break;

                case Device.UWP:
                    smallImage = "bank.png";
                    break;
                }

                Application.Current.Resources.Add("SomeSmallImage", smallImage);
            }

            const string instructions1 = @"Tap the Start button and follow the instructions on the next page.";
            string       instructions2 =
                $"When you return to this page, tap the Collect button. The message \n'{Bugzilla42069_Page.DestructorMessage}'\n should appear at least once in the debug output.";

            var label1 = new Label {
                Text = instructions1
            };
            var label2 = new Label {
                Text = instructions2, HorizontalTextAlignment = TextAlignment.Center
            };

            var startButton = new Button {
                Text = "Start"
            };

            startButton.Clicked += (sender, args) =>
            {
                // We have to do the push-pop-push dance because NavigationPage
                // holds a reference to its last page for unrelated reasons; our concern
                // here is that the first Bugzilla42069_Page that we pushed gets collected
                PushAsync(new Bugzilla42069_Page(), false);
                PopAsync(false);
                PushAsync(new Bugzilla42069_Page(), false);
            };

            var collectButton = new Button {
                Text = "Collect"
            };

            collectButton.Clicked += (sender, args) =>
            {
                GarbageCollectionHelper.Collect();
            };

            var startPage = new ContentPage
            {
                Content = new StackLayout
                {
                    Children =
                    {
                        label1,
                        startButton,
                        label2,
                        collectButton
                    }
                }
            };

            PushAsync(startPage);
        }
Exemplo n.º 22
0
            async void Button_Clicked(object sender, EventArgs e)
            {
                GarbageCollectionHelper.Collect();

                await Navigation.PushAsync(new ChildPage());
            }
Exemplo n.º 23
0
 protected override void OnAppearing()
 {
     base.OnAppearing();
     GarbageCollectionHelper.Collect();
     otherLabel.Text = Success;
 }
Exemplo n.º 24
0
 protected override void OnAppearing()
 {
     base.OnAppearing();
     GarbageCollectionHelper.Collect();
 }