Bug 25223 - IOS: MasterDetailPage does not dispose child renderers correctly
Summary: IOS: MasterDetailPage does not dispose child renderers correctly
Status: VERIFIED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-12-10 07:20 UTC by azinner
Modified: 2015-01-14 05:42 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Sample solution (3.45 MB, application/zip)
2014-12-22 07:01 UTC, azinner
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description azinner 2014-12-10 07:20:38 UTC
Although this is listed as a resolve bug in the 'Bug fixes' section of the prerelease 2,
when a (detail) page, that contains a map, is disposed during the assignment of a new detailPage, the app crashes on IOS.

Example code:

using System;
using Xamarin.Forms;
using Xamarin.Forms.Maps;

namespace MasterDetail
{
   public class App : Application
   {
      MasterDetailPage _masterDetailPage = null;

      public App ()
      {
         _masterDetailPage = new MasterDetailPage {

            Master = new ContentPage {
               Title = "Master",
               Content = new Button { 
                  Text = "Click to crash",
                  Command = new Command (o =>
                  {
                     // When this new detail page is assigned,
                     // the disposing of the previous seletced detail page with the map crashes ....
                     _masterDetailPage.Detail = new NavigationPage (new ContentPage{ });
                  })
               }
            },

            Detail = new NavigationPage (
               new ContentPage { 
                  Content = new Map () 
               })
         };

         MainPage = _masterDetailPage;
      }
   }
}

Stack trace:

System.NullReferenceException: Object reference not set to an instance of an object
at Xamarin.Forms.Maps.iOS.MapRenderer.Dispose (Boolean disposing) [0x00000] in <filename unknown>:0
at MonoTouch.Foundation.NSObject.Dispose () [0x00000] in /Developer/MonoTouch/Source/maccore/src/Foundation/NSObject2.cs:127
at Xamarin.Forms.Platform.iOS.Platform.DisposeModelAndChildrenRenderers (Xamarin.Forms.Element view) [0x00000] in <filename unknown>:0
at Xamarin.Forms.Platform.iOS.Platform.HandleChildRemoved (System.Object sender, Xamarin.Forms.ElementEventArgs e) [0x00000] in <filename unknown>:0
at Xamarin.Forms.Element.OnDescendantRemoved (Xamarin.Forms.Element child) [0x00000] in <filename unknown>:0
at Xamarin.Forms.Element.OnChildRemoved (Xamarin.Forms.Element child) [0x00000] in <filename unknown>:0
at Xamarin.Forms.Page.OnInternalRemoved (Xamarin.Forms.VisualElement view) [0x00000] in <filename unknown>:0
at Xamarin.Forms.Page.InternalChildrenOnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <filename unknown>:0
at System.Collections.ObjectModel.ObservableCollection`1[Xamarin.Forms.Element].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00014] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/System/System.Collections.ObjectModel/ObservableCollection.cs:161
at System.Collections.ObjectModel.ObservableCollection`1[Xamarin.Forms.Element].RemoveItem (Int32 index) [0x0001a] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.4.0.43/src/mono/mcs/class/System/System.Collections.ObjectModel/ObservableCollection.cs:182
at System.Collections.ObjectModel.Collection`1[Xamarin.Forms.Element].Remove (Xamarin.Forms.Element item) [0x00011] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Collections.ObjectModel/Collection.cs:134
at Xamarin.Forms.MasterDetailPage.set_Detail (Xamarin.Forms.Page value) [0x00000] in <filename unknown>:0
at MasterDetail.App.<App>m__0 (System.Object o) [0x00011] in /Users/Andre/Projekte/mobile/MasterDetail/MasterDetail/App.cs:23
at Xamarin.Forms.Command.Execute (System.Object parameter) [0x00000] in <filename unknown>:0
at Xamarin.Forms.Button.Xamarin.Forms.IButtonController.SendClicked () [0x00000] in <filename unknown>:0
at Xamarin.Forms.Platform.iOS.ButtonRenderer.OnButtonTouchUpInside (System.Object sender, System.EventArgs eventArgs) [0x00000] in <filename unknown>:0
at MonoTouch.UIKit.UIControlEventProxy.Activated () [0x00007] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIControl.cs:33
at at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:62
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:46
at MasterDetail.iOS.Application.Main (System.String[] args) [0x00008] in /Users/Andre/Projekte/mobile/MasterDetail/iOS/Main.cs:17


Work around: in OnDisappearing() of the page that contains the map I manually set "Content = null;".
But this may cause memory leaks ...
Comment 1 Lynn Koehler 2014-12-18 15:20:46 UTC
I'm running pre-3 of Forms and Maps and have this same problem - but only when the new detail page is replacing a page with a map in the Content.
Comment 2 Parmendra Kumar 2014-12-22 03:43:35 UTC
I have tried to reproduce this issue but I am not able to reproduce this.Please check the screencast and let me know if I have missed anything. Could you please provide us sample project, steps and environment info.? That can be helpful to reproduce at my end.

Screencast: http://www.screencast.com/t/H2uhhIDbr00
Comment 3 azinner 2014-12-22 07:01:16 UTC
Created attachment 9162 [details]
Sample solution

I can reproduce with the latest stable or beta channels:

XS 5.5.4
IOS 8.4.0.47
MDK 3.10.0.31
Comment 4 Parmendra Kumar 2014-12-22 07:30:20 UTC
I have checked this issue with attached sample in comment 3. I am getting same behavior mentioned in the bug description. 

Screencast: http://www.screencast.com/t/LbXlUlFA

ApplicationOutput: https://gist.github.com/Arpit360/a36a50986283282c5e42
BuildLog: https://gist.github.com/Arpit360/761308699661974c07a0
IdeLog: https://gist.github.com/Arpit360/f750e835f6443ced97cd

Environment info:

=== Xamarin Studio ===

Version 5.5.4 (build 15)
Installation UUID: 3d25a767-a003-4a7d-9f5e-e57987cf6cf0
Runtime:
	Mono 3.10.0 ((detached/92c4884)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000031

=== Apple Developer Tools ===

Xcode 6.1 (6602)
Build 6A1052c

=== Xamarin.Mac ===

Version: 1.10.0.18 (Enterprise Edition)

=== Xamarin.Android ===

Version: 4.20.0.28 (Enterprise Edition)
Android SDK: /Users/mac360_xamarin/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin.iOS ===

Version: 8.4.0.47 (Enterprise Edition)
Hash: 7244769
Branch: 
Build date: 2014-12-11 14:54:30-0500

=== Build Information ===

Release ID: 505040015
Git revision: f93940a35458a18052f1a25e106e62ca970d9c40
Build date: 2014-11-19 15:32:41-05
Xamarin addins: dc23cbd91a3a0e1d326328e1229e86c942a49ec8

=== Operating System ===

Mac OS X 10.10.0
Darwin mac360-xamarins-Mac-mini.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 5 Jason Smith [MSFT] 2015-01-13 20:57:19 UTC
This no longer crashes in 1.3.1
Comment 6 Parmendra Kumar 2015-01-14 05:19:13 UTC
I have checked this issue with Xamarin.Forms 1.3.1 and now application don't crash.

Screencast: 

Hence Closing this issue. Please reopen this issue if you getting same issue.

Environment info:

 Xamarin.Forms 1.3.1.6296
Xamarin Studio  5.7 (build 661)
Mono 3.12.0 ((detached/1538a59)
Xcode 6.1 (6602)
 Xamarin.iOS: 8.6.0.52 (Enterprise Edition)
Xamarin.Mac: 1.11.3.0 (Enterprise Edition)
Mac OS X 10.9.4
Comment 7 Parmendra Kumar 2015-01-14 05:42:21 UTC
Screencast: http://www.screencast.com/t/mzTAaayhl