[Mono-bugs] [Bug 534515] MonoTouchCell Example with Webservice Call.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Aug 26 15:09:27 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=534515

User gnorton at novell.com added comment
http://bugzilla.novell.com/show_bug.cgi?id=534515#c1


Geoff Norton <gnorton at novell.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |gnorton at novell.com
         Resolution|                            |INVALID




--- Comment #1 from Geoff Norton <gnorton at novell.com>  2009-08-26 13:09:25 MDT ---
Phil,

  Whats happening here is your DetailViewController is being GC'd.  Let me try
to explain:

In AppDelegate.g.cs you have:

        [Connect]                                                               
        public DetailViewController detailViewController {
                get { return (DetailViewController) GetNativeField
("detailViewController"); }
                set { SetNativeField ("detailViewController", value); }
        }

Which tells MonoTouch that you want a field on the Obj-C counterpart to the
appDelegate to store the detailViewController so that it is accessible from
Obj-C.

Then in AppDelegate.cs you have:

        detailViewController = new DetailViewController
("DetailViewController", null);
        detailViewController.LoadView();

Which does this step by step:

var d = new DetailViewController ("DetailViewController", null);

Create a new (M)anaged DetailViewController and its (N)ative counterpart.  The
managed GC has a ref to M and the native object has a ref count of 1.

detailViewController = d;

Set the native field on the AppDelegate.detailViewController to the native
object of the detailviewcontroller.  Ref count is still 1 in (M) and (N).

Then control leaves the scope of FinishedLaunching, meaning the managed ref
goes away.  The next time the GC runs, it Collects the managed
detailviewcontroller object.  The detailviewcontroller finalizer removes the
native ref, causing the NSAutoReleasePool to delete the native counterpart,
making the AppDelegate.detailViewController native field point to an invalid
handle.

For your case the way to fix this is:

Remove from AppDelegate.g.cs:

        [Connect]                                                               
        public DetailViewController detailViewController {
                get { return (DetailViewController) GetNativeField
("detailViewController"); }
                set { SetNativeField ("detailViewController", value); }
        }

Add to AppDelegate.cs:

    DetailViewController detailViewController;


Does that make sense?

-g

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list