ios - Not calling dealloc on UIViewController in Xamarin -
i have uiviewcontroller
written in native library bound xamarin app. controller has method follows:
+ (instancetype)newinstance { return [shareddata.sharedinstance.mainstoryboard instantiateviewcontrollerwithidentifier:@"worksheetcontroller"]; }
this method bound xamarin app follows:
// @interface worksheettableviewcontroller : uiviewcontroller [basetype(typeof(uiviewcontroller))] interface worksheettableviewcontroller { // +(instancetype)newinstance; [static] [export("newinstance")] worksheettableviewcontroller newinstance(); }
now in xamarin app in uiviewcontroller
subclass in viewdidload call method follows:
this.worksheetcontroller = worksheettableviewcontroller.newinstance();
the worksheetcontroller
not used anywhere else in uiviewcontroller
. when uiviewcontroller
disposed (by popping off navigation stack), dealloc
method of worksheettableviewcontroller
not called.
however if change code in viewdidload follows:
this.worksheetcontroller = (worksheettableviewcontroller)shareddata.sharedinstance.mainstoryboard.instantiateviewcontroller("worksheetcontroller");
when uiviewcontroller
disposed, dealloc method gets called.
to me there doesn't seem difference in newinstance
method in native code , directly calling instantiateviewcontroller
in xamarin. yet in former case dealloc
not being called, while fine in later.
can explain why memory management different in 2 cases?
this because arc implicitly retain return value native newinstance
method [1], , xamarin.ios not implicitly detect that.
you have 2 options:
rename native method doesn't start
new
orcopy
(there few other prefixes well, see [1] full list), arc doesn't automatically retain return value.add
[return: release ()]
api definition (this tells xamarin.ios arc doing, , xamarin.ios add additionalrelease
call):[static] [export("newinstance")] [return: release ()] worksheettableviewcontroller newinstance();
[1] http://clang.llvm.org/docs/automaticreferencecounting.html#method-families
Comments
Post a Comment