On Fri, Oct 7, 2011 at 15:51, Nic Wise <[email protected]> wrote:
> My understanding is that a using is basically this:
>
> try {
>  //stuff
> } finally {
>  theVariable.Dispose();
> }
>
> where as without the using, you are waiting for the GC to collect it,
> which is a non-deterministic thing (might be immediate, might take a
> looooong time, might even be never!)

Indeed, the using statement disposes of the variable, which would occur
before the alert is shown. To free resources asap, I've added a
Dispose() in the 'clicked' delegate of the alert:

button.Clicked += delegate {
    var alert = new UIAlertView {Title = "alert", Message = "message" };
    alert.AddButton("yes");
    alert.AddButton("no");
    alert.Clicked += delegate(object sender, UIButtonEventArgs e) {
        if (e.ButtonIndex == 0) {
            label.Text = "we got a 'yes'";
        }
        else
        {
            label.Text = "too bad...";
        }
        alert.Dispose();
    };
    alert.Show();
};

Still puzzled why the sigsegv does not occur when starting the installed
app on the simulator: that always works. GC must be runnng a different
schedule then. Similarly, the using clause works fine on the device.

Guido
_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to