title: Xamarin NSNotificationCenter: When to call RemoveObserver?
body: <p>In my <code>UIViewController</code>, <code>viewDidLoad</code> method I am subscribing to a notification as follows:</p>
  
  <pre><code>public override void ViewDidLoad()
  {
     base.ViewDidLoad();
  
     this.disposable = NSNotificationCenter.DefaultCenter.AddObserver("UserUpdated", () =&gt; UserUpdated());
  }
  </code></pre>
  
  <p>My question is where do I remove the observer so that there is no memory leak. Normally in Objective-C, I would remove it in the <code>dealloc</code> method.</p>
  
  <p>But if I try to <code>Dispose</code> the <code>disposable</code> above in the <code>Dispose</code> method or in the destructor, there is a memory leak because of a cycle. What is the best way to prevent this memory cycle?</p>
  
  <p>Note: I cannot use <code>ViewWillAppear/ViewWillDisappear</code> as my methods to add/remove the observer since I need access to it when the view of the view controller is not in the foreground.</p>