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

Reply via email to