# Trouble with dialog based application

**URL:** <https://www.ruby-forum.com/t/trouble-with-dialog-based-application/116788>\
**Category:** wxRuby\
**Created:** [October 9, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/trouble-with-dialog-based-application/116788 "2007-10-09T20:00:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [October 9, 2007, 8:00pm UTC](https://www.ruby-forum.com/t/trouble-with-dialog-based-application/116788/1 "2007-10-09T20:00:00Z")

</div>

Hi,

A long time ago, I made some MFC GUI programming …  
There was basically 2 kinds of application :

- dialog based application : a simple app based on a dialog (without  
menu, toolbar, status bar …)
- frame based app (Single Document or Multiple Document) with menu,  
toolbar, status bar …

I tried to make a dialog based app with wxRuby but the application  
never exits !!

The following code based on a frame works as expected.  
After the closing of the application window, the “exit from  
application” string is output.

require “wx”

class HelloWorld \< Wx::App  
def on\_init  
helloframe = Wx::Frame.new(nil, “Hello World”)  
Wx::StaticText.new(helloframe, “Hello World”)  
helloframe.show  
end  
end

HelloWorld.new.main\_loop  
puts “exit from application”

If the frame is replaced by a dialog, the application seems to be  
closed but the message is never output.  
I tried both show and show\_modal to display the window.

require “wx”

class HelloWorld \< Wx::App  
def on\_init  
hellodlg = Wx::Dialog.new(nil, “Hello World”)  
Wx::StaticText.new(hellodlg, “Hello World”)  
hellodlg.show\_modal

# hellodlg.show

end  
end

HelloWorld.new.main\_loop  
puts “exit from application”

=\> Am I doing something wrong ?

Cheers.

Chauk-Mean.

---

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [October 9, 2007, 11:06pm UTC](https://www.ruby-forum.com/t/trouble-with-dialog-based-application/116788/2 "2007-10-09T23:06:27Z")

</div>

Hi Chauk-Mean

Chauk-Mean P wrote:

> If the frame is replaced by a dialog, the application seems to be  
> closed but the message is never output.  
> I tried both show and show\_modal to display the window.

If you have a parent-less dialog, you probably need to call destroy() on  
the dialog when it closes to ensure it’s really killed.

[http://wxruby.rubyforge.org/doc/dialog.html#Dialog\_destroy](http://wxruby.rubyforge.org/doc/dialog.html#Dialog_destroy)

hth  
alex

---

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [October 10, 2007, 4:48pm UTC](https://www.ruby-forum.com/t/trouble-with-dialog-based-application/116788/3 "2007-10-10T16:48:33Z")

</div>

2007/10/9, Alex F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > 
> 
> If you have a parent-less dialog, you probably need to call destroy() on  
> the dialog when it closes to ensure it’s really killed.
> 
> [http://wxruby.rubyforge.org/doc/dialog.html#Dialog\_destroy](http://wxruby.rubyforge.org/doc/dialog.html#Dialog_destroy)

Thanks Alex. I missed this subtlety.

Nevertheless, this raises another question. As Ruby has garbage  
collection (unlike c++ WxWidgets) , it would be great if a Wx::Dialog  
without a parent can call destroy itself when the Ruby object is about  
to be destroyed.  
This would simplify the usage of Wx::Dialog and makes it behave like a  
Frame with no parent.

Cheers.

Chauk-Mean.

---

<div class="post-metadata">

**Author:** ![chauk-mean](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/d07c76/32.png) [@chauk-mean](https://www.ruby-forum.com/u/chauk-mean)\
**Post date:** [October 11, 2007, 4:05am UTC](https://www.ruby-forum.com/t/trouble-with-dialog-based-application/116788/4 "2007-10-11T04:05:37Z")

</div>

Chauk-Mean P wrote:

> As Ruby has garbage collection (unlike c++ WxWidgets) , it would be great if a Wx::Dialog  
> without a parent can call destroy itself when the Ruby object is about  
> to be destroyed.  
> I agree; I’ve wanted to fix this ‘subtlety’, as you put it, politely.  
> It’s come up before on the m.l.

However, it’s a bit tricky and I don’t know how to solve it. The order  
of destruction of all GUI objects is always wxWidgets first, then ruby’s  
garbage collection to clean up the ruby object at some point later. By  
the time a ruby GC hook could run, the C++ object is dead and gone.

Also, wxWidgets doesn’t consider a parentless Dialog destroyed when it’s  
closed, unlike frames. I guess it assumes a dialog-based app might want  
to close and re-show the same Dialog several times.

cheers  
alex
