title: Xamarin Android Activities/ Fragments not being garbage collected
body: <p>I'm building a Xamarin Android app.
  This app seems to consume more memory than the usual java/kotlin ones. I understand some memory is used by Xamarin framework itself. I did some test to check if objects are being garbage collected.</p>
  <p>In order to test this I added destructors to different objects  <code>~MyClass(){ }</code>, put breakpoints and I could see C# objects being claimed by GC. In Fragment/Activities the destructors were not called even after <code>OnDestroy()</code>.
  The simplest example to show this is a <code>SplashActivity</code> that just starts the <code>MainActivity</code> of my app.</p>
  <pre><code>  [Activity(Label = &quot;@string/app_name&quot;, MainLauncher = true, LaunchMode = Android.Content.PM.LaunchMode.SingleTop, ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait, Theme = &quot;@style/SplashTheme&quot;)]
    public class SplashActivity : AppCompatActivity
    {
      MyCSharpClass myObject; // this is not garbage collected
   
      protected override void OnCreate(Bundle bundle)
      {
          myObject = new MyCSharpClass();
       
          base.OnCreate(bundle);
          var intent = new Intent(this, typeof(MainActivity));
          StartActivity(intent);
          Finish();
      }
     
      protected override void OnDestroy() //this is called
      {
          base.OnDestroy();
      }
  
      ~SplashActivity() // this is not called
      {
  
      }
  }
  </code></pre>
  <p><code>OnDestroy</code> is called immediately but the destructor <code>~SplashActivity()</code> is never called.
  So the fragment/activity and it's pure C# properties/fields seem to remain in memory.
  I know that these are <code>Java.Lang.Object</code> types but I would expect Android and C# Garbage Collectors to work together to clear the objects.</p>
  <p>What is the proper way to make <code>SplashActivity</code> and <code>myObject</code> to be removed from memory?</p>