Hi Klaus,
On 17/2/22 13:00, Klaus Rudolph <lts-rudolph gmx de> wrote:
<snip>I want to create some windows on demand with "new". If the user closes the window, when I can call delete on that class derived from Gtk::Dialog or Gtk::Window?
void on_hide() override { std::cout << "Hide event" << std::endl; delete this; // is it safe to delete our self here????? }
I tested you example and it works whenever the user closes the windows in the reverse order from creation. But, what happens if the user closes the parent window first? In that case, the destructor of the child window won't be called and this isn't safe because you are using raw pointers instead of smart pointers.
On the other hand, bear in mind that new windows can be created from both the parent and the child all over again. Therefore, I guess that you should use a weak pointer together with a shared one to keep track of the nodes in the tree.
My2Cents,
Aitor.