title: Strange crash when using the new PageCurl effect reading a PDF with MonoTouch and iOS 5.0
body: <p>I get a strange crash when using the new PageCurl effect reading a PDF with MonoTouch and iOS 5.0.
  I've made a simple test case project for MonoDevelop 2.8 and uploaded on GitHub here:</p>
  
  <p><a href="https://github.com/Emasoft/IpaziaPDFReader" rel="nofollow">https://github.com/Emasoft/IpaziaPDFReader</a></p>
  
  <p>It seems that something is getting GCd too early and killing the application, but I can't find what. I've tried to dispose everything in many ways, but in vain. I've already submitted the project tarball to the Xamarin team, but they weren't able to  solve the problem.</p>
  
  <p>Is there something broken in the iOS NavigationController memory management? Or am I missing something?</p>
  
  <p>Any help is appreciated, thanks!</p>
  
  <p>UPDATE: I've tried to remove all subviews and sublayers before disposing the objects in all classes, but it still crashing. The only way I found to avoid the crash is to NEVER dispose of the PDF pages, adding them to a List before releasing them, but this is not a viable solution, because in that way memory is consumed rapidly for PDF with many pages and the app crashes anyway when unable to allocate memory for the next page.
  Another way to avoid the crashes is to dispose of the PDF pages BEFORE turning the pages, forcing the dispose method on the page controller before creating a new page controller, but in this way the current page will become blank and the transition curls an useless empty page. No solution seems to work. </p>
  
  <p>I've updated project on GitHub with the 3 different solutions I've tried (look in the PageDataSource class), you can uncomment them one at time to see the problems.</p>
  
  <pre><code>        //SOLUTION 1   
      void ForcingPageControllerDispose (BookPageController oldPageController)
      {
          // --- IF YOU UNCOMMENT THIS, THE CRASHES GO AWAY, BUT THE PAGE IN THE TRANSITION IS BLANK, SO IS NOT VIABLE
          currentPageController.View.RemoveFromSuperview ();
          currentPageController.Dispose ();
      }
  
  
      //SOLUTION 2
      void DisposeThePageControllerWhenDidFinishAnimating (BookPageController oldPageController, UIPageViewController pageViewController)
      {
          // --- IF YOU UNCOMMENT THIS, THE CRASHES STILL HAPPEN
          pageViewController.DidFinishAnimating += delegate(object sender, UIPageViewFinishedAnimationEventArgs e) {
              if (currentPageController != null) {
                  currentPageController.View.RemoveFromSuperview ();
                  currentPageController.Dispose ();
                  Console.WriteLine ("currentPageController disposed for page: " + currentPageController.PageIndex);
              }
          };
      }
  
  
      //SOLUTION 3
      void BackupUnusedPagesToAvoidBeingGCd (BookPageController oldPageController)
      {
          // --- IF YOU UNCOMMENT THIS, THE CRASHES GO AWAY, BUT THE PAGES ARE NOT GARBAGE COLLECTED AND AFTER MANY PAGES IPHONE IS OUT OF MEMORY AND IT CRASHES THE APP
          if (parentController.book_page_controllers_reference_list.Contains (currentPageController) == false)
              parentController.book_page_controllers_reference_list.Add (currentPageController);
      }
  </code></pre>