On Wed, Jan 23, 2013 at 1:37 AM, Rolf Bjarne Kvinge <[email protected]>wrote:

> This is due to an optimization, we do not make instances of non-inherited
> framework types track the life-time of their corresponding native/ObjC
> object.
>

Thanks for the reply. Can you explain a bit further?

For example, I don't understand why Mono/C# tracking the lifetime of the
native object is related to the native UIView tracking the lifetime of the
native UIButton. I expect my "UIView.AddSubview(UIButton)" to cause the
native UIView to hold a reference to the native UIButton alive, even if the
C# wrapper object was collected.

...or is this a problem with my "target" delegate being collected, and not
the UIButton itself?

This problem is one that I run into frequently when using Xamarin. Because
my UI is instantiated in code, my classes are filled
with superfluous instance variables holding views and delegates simply to
avoid them being prematurely collected. Subclassing every one of those
would be even more cumbersome than making them instance variables. I
encourage you to reconsider this optimization, as it's a constant
re-occuring "surprise" when these objects being collected cause segfaults.

I don't know much about the details of how the Xamarin C# mirrors work, but
I would think there would be a way to make the API put a mirror in place
anytime a native object is returned without breaking the native-to-native,
or native-to-C#-delegate lifetime tracking.
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to