Hi,
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.
Your example will work correctly if you use a class derived from UIButton:
class MyButton : UIButton { ... }
Best regards,
Rolf
On Tue, Jan 22, 2013 at 7:35 PM, David Jeske <[email protected]> wrote:
> I'm having trouble with MonoTouch segfaults. It seems to be related to
> programming patterns where I expect iOS objects to "own" objects I created
> in MonoTouch, such as the following code in a view init method. I am using
> SGen and the "reference counting extension - preview" because they seemed
> like they would make this better, but they didn't.
>
> {
> UIButton reRollButton = new UIButton(new
> RectangleF(20,0,Bounds.Width-40 ,40));
> reRollButton.SetTitle("Re-Roll",UIControlState.Normal);
> reRollButton.AddTarget(delegate(object sender, EventArgs e) {
> this.SetupNewRandomWords();
> } ,UIControlEvent.TouchUpInside);
>
>
> reRollButton.SetBackgroundImage(controller.glassButtonBackground,UIControlState.Normal);
> slView.AddSubview(reRollButton);
> }
>
>
> If I make "reRollButton" a class instance variable, I don't see a crash.
> As a result, it seems like the problem is that the garbage collector is not
> honoring the AddRef that happens inside AddSubview. Any Idea why that is?
> This seems to me like a pretty fundamental problem in Objective-C / C#
> objective lifetime compatibility. Am I mis-understanding something? How do
> I get object-lifetime to work correctly?
>
> _______________________________________________
> MonoTouch mailing list
> [email protected]
> http://lists.ximian.com/mailman/listinfo/monotouch
>
>
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch