Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How come class is not "released" and GC'ed ?

$
0
0

Hi

Could someone please make it clear for me, how come the "ticket" variable keeps adding up, everytime the button is clicked ? I though the garbage collector should remove it automatically ? Even when i try to call GC.Collect explicit, it still keeps adding up in the Xamarin Profiler.

namespace ScannerAppCross
{
    public class TestPage : BaseContentPage
    {
        Ticket ticket;
        public TestPage ()
        {
            var b = new Button { Text = "Alloc" };
            b.Clicked += (sender, e) => {

                ticket = new Ticket ();
            };

            var g = new Button { Text = "GC" };
            g.Clicked += (sender, e) => {

                ticket = null;
            };

            Content = new StackLayout {
                Padding = 20,
                Children = {
                    b, 
                    g,
                }
            };
        }   
    }

    public class Ticket
    {
        public string id { get; set; }
    }
}

Is there something fundemental that I'm missing here ?? I sure hope so ;-)

Regards,
Kent Fonager


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>