title: Xamarin memory reclaim issues
body: <p>I have used Xamarin for a while now, and I have encountered a very strange issue.</p>
  
  <p>I am able to crash a very simple two screens app. On the first screen, I have a <code>UIButton</code> with the <code>TouchUpInside</code> event. On the second, I have a <code>UIImageView</code> with attached image (from local file). </p>
  
  <p>All I have to do is to move back and forward between those two View-Controllers, all the time. </p>
  
  <p>When I attached XCode's Instruments with Activity Monitor on, I noticed that my simple app reaches ~100MB of memory before the memory gets reclaimed, then its usage drops to ~15MB. </p>
  
  <p>But when I loop navigation long enough, memory reaches over 140MB and the app crashes. I have discovered this behaviour while working on a more complex app. Of course, I am taking all available precautions: </p>
  
  <ul>
  <li>unsubscribing events on ViewWillDisappear</li>
  <li>nulling the delegates and so on. </li>
  </ul>
  
  <p>Basicly, in my complex app, I have overriden the <code>Dispose</code> method in my base class for all <code>UIViewControllers</code>, and I can see that the <code>Dispose</code> method is called with <code>disposing == false</code> on every view controller that was displayed. However, the memory usage doesn't drop. </p>
  
  <p>What is wrong with it?</p>
  
  <p>I would like to point out few things:</p>
  
  <ul>
  <li>My Xamarin Studio is up to date,</li>
  <li>Crashes appeared while I was testing applications in debug mode on iPhone 3GS iOS 6.1.3</li>
  <li>In simple appplication, the image was a 1024x1024 JPG file.</li>
  </ul>
  
  <p>Herewith some code sample:</p>
  
  <pre><code>public partial class SimpleTestViewController : UIViewController 
  {
      private UIButton button;
      public SimpleTestViewController () : base ("SimpleTestViewController", null) { }
  
      public override void DidReceiveMemoryWarning ()
      {
          // Releases the view if it doesn't have a superview.
          base.DidReceiveMemoryWarning ();
  
          // Release any cached data, images, etc that aren't in use.
      }
  
      public override void ViewDidLoad ()
      {
          base.ViewDidLoad ();
          button = new UIButton (new RectangleF(0, 100, 100, 50));
          button.BackgroundColor = UIColor.Red;
          button.TouchUpInside += (sender, e) =&gt; {
              this.NavigationController.PushViewController(new SecondView(), true);
          };
          this.Add (button);
  
          // Perform any additional setup after loading the view, typically from a nib.
      }
  }
  
  public partial class SecondView : UIViewController
  {
      private UIImageView _imageView;
  
      public SecondView () : base ("SecondView", null) { }
  
      public override void DidReceiveMemoryWarning ()
      {
          // Releases the view if it doesn't have a superview.
          base.DidReceiveMemoryWarning ();
  
          // Release any cached data, images, etc that aren't in use.
      }
  
      public override void ViewDidLoad ()
      {
          base.ViewDidLoad ();
  
          _imageView = new UIImageView (new RectangleF(0,0, 200, 200));
          _imageView.Image = UIImage.FromFile ("Images/image.jpg");
          this.Add (_imageView);
          // Perform any additional setup after loading the view, typically from a nib.
      }
  
      protected override void Dispose (bool disposing)
      {
          System.Diagnostics.Debug.WriteLine("Disposing " +this.GetType() 
              + " hash code " + this.GetHashCode() 
              + " disposing flag "+disposing);
          base.Dispose (disposing);
      }
  }
  </code></pre>