[Gtk-sharp-list] widget destruction

Mike Kestner mkestner at gmail.com
Tue Mar 8 21:12:43 EST 2011


On Tue, Mar 8, 2011 at 5:22 PM, Christopher David Howie
<me at chrishowie.com>wrote:


>  -----------------------8<-----------------------
>     FooDialog d;
>     try {
>         d = new FooDialog();
>         d.Run();
>     } finally {
>         if (d != null) {
>             d.Destroy();
>             d.Dispose();
>         }
>     }
>

The try/finally above accomplishes nothing.  The d.Run() call results in a
native transition.  The only possible exception you can receive during that
call would be related to an inability to pinvoke libgtk which presumably
would have stopped you long before this point.  Once the transition to
gtk_dialog_run has occurred, no exception propagation will or can come back
across the native boundary.  Doing a Destroy would similarly fail pinvoke
for any scenario regarding exceptions coming out of d.Run.  d != null fails
for dialog constructor exceptions.  The Dispose call is redundant since
Destroy calls Dispose.  I'm assuming this Destroy+Dispose pattern evolved
from people writing Dispose, finding out they really needed to Destroy
instead, and forgetting or not knowing they could remove the Dispose.

The above code is therefore no more robust than:

var d = new FooDialog ();
d.Run ();
d.Destroy ();

The fact that people as knowledgable with Gtk# may be writing code like that
though is a somewhat convincing argument that we have an opportunity to
improve the binding here.

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20110308/6bfc3b28/attachment.html 


More information about the Gtk-sharp-list mailing list