title: How can I remove / garbage collect an attached method from a tabbarController.ViewControllerSelected event?
body: <p>I have this code that attaches: <code>OnTabbarControllerItemSelected;</code> to  <code>tabbarController.ViewControllerSelected</code>.  From what I understand events like this that are attached should also be detached later.  </p>
  
  <p>Can someone give me advice on where I should do the detach. Also should I override the Dispose method for this code and if so how should I do that?  </p>
  
  <p>Code:</p>
  
  <pre><code>    protected override void OnElementChanged(VisualElementChangedEventArgs e)
      {
          base.OnElementChanged(e);
  
          if (e.NewElement != null)
          {
              _page = (MainPage)e.NewElement;
          }
          else
          {
              _page = (MainPage)e.OldElement;
          }
  
          if (e.OldElement != null)
          {
              Xamarin.Forms.Application.Current.PropertyChanged -= Current_PropertyChanged;
              return;
          }
  
          try
          {
              var tabbarController = (UITabBarController)this.ViewController;
  
              if (null != tabbarController)
              {
                  Xamarin.Forms.Application.Current.PropertyChanged += Current_PropertyChanged; //subscribe to the App class' built in property changed event
                  tabbarController.ViewControllerSelected += OnTabbarControllerItemSelected;
  
                  UpdateTheme();
              }
          }
          catch (Exception exception)
          {
              Console.WriteLine(exception);
          }
      }
  </code></pre>
  
  <p>Would appreciate some advice on how I can detach this method in a similar way to the way that the <code>Current_PropertyChanged</code> method is being detached.</p>