xamarin.ios - No constructor found for ViewController::.ctor(System.IntPtr) -
i'm having issue monotouch application crashes after receiving memory warning. please see stack trace below.
received memory warning. level=2 dtmobileis[2299] : _memorynotification : { osmemorynotificationlevel = 2; timestamp = "2011-04-11 14:29:09 +0000"; } toplevel exception: system.missingmethodexception: no constructor found myapp.ui.boardcontroller::.ctor(system.intptr) @ system.activator.createinstance (system.type type, bindingflags bindingattr, system.reflection.binder binder, system.object[] args, system.globalization.cultureinfo culture, system.object[] activationattributes) [0x00000] in :0 @ system.activator.createinstance (system.type type, system.object[] args, system.object[] activationattributes) [0x00000] in :0 @ system.activator.createinstance (system.type type, system.object[] args) [0x00000] in :0 @ monotouch.objcruntime.runtime.constructnsobject (intptr ptr, intptr klass) [0x00000] in :0 @ monotouch.objcruntime.runtime.getnsobject (intptr ptr) [0x00000] in :0 @ monotouch.objcruntime.runtime.getnsobjectwrapped (intptr ptr) [0x00000] in :0 @ (wrapper native-to-managed) monotouch.objcruntime.runtime:getnsobjectwrapped (intptr) @ monotouch.uikit.uiapplication.main (system.string[] args, system.string principalclassname, system.string delegateclassname) [0x00000] in :0 @ myapp.free.application.main (system.string[] args) [0x00000] in /users/haakon/code/myapp-work/ios/myapp.free/myapp.free/main.cs:12 the stack trace correct in indicated class (boardcontroller, uiviewcontroller subclass) lacks constructor taking intptr parameter. intentional don't use interface builder @ in application. why happen?
i did find similar question seemed suggest can happen if allow views (or possibly view controllers) become garbage collected. don't see how can happen here. background: application delegate holds strong reference navigation controller, in turn holds strong reference root view controller in navigation stack. root view controller holds strong reference boardcontroller instance. don't understand how it's possible boardcontroller gets garbage collected.
any ideas?
the intptr constructor used when native object needs surfaced managed object. in particular case, creating, this:
var foo = new foo (); someobject.property = foo; this assigns foo object property, if property objective-c object, if not keep reference "foo", mono's gc go ahead , dispose linkage between managed foo , unmanaged foo.
then, later on, try retrieve it:
var bar = someobject.property; here, monotouch know there no managed object anymore maps it, has construct new one, has intptr objective-c code. why need constructor.
you might tempted add native constructor, , fine in many cases, problem if object has own state stored in managed world, example:
public class foo : uiview { string name; public foo () { name= "hello"; } public foo (intptr ptr) : base (ptr) {} } in case, intptr constructor can not reconstruct managed object , state merely intptr. source of problem not keeping reference object.
so real fix in short is: keep reference boardcontroller in managed code prevent object being collected when still going use later on.
Comments
Post a Comment