GTK4 creating and destroying new toplevel windows

I’m new to GTK4 and trying to test a few things and wrap my head around some basic concepts. Ebassi’s and Chrstian Herget’s videos on GObject etc have been very helpful, but I’m trying to apply some basics.

When I compile the following app against GTK4 4.6.6 I get unexpected behavior. Whenever I repeatedly click the “New Stack!” button and create many new top level windows, then try to exit the app, it does not do so gracefully and leaves many top level windows still open. When I do it with just a few, it seems to have expected behavior and close out the additional top level windows. Any insight/input is appreciated.

Source is located at View paste VY2Q

I had a glance through your code, but nothing stuck out as obviously wrong to me. Maybe I can point you in the right direction, though.

The way a GApplication is kept running (instead of just invoking ::startup and exiting) is by making a call to g_application_hold(), which will keep the application looping for events until a matching call to g_application_release() is called (you can have more than one active hold).

Creating a window bound to a GApplication (i.e. pass the GApplication as the application property) more or less does the same thing, with g_application_release() being called when the window is destroyed. When the last “hold” is released, ::quit is invoked.

That being said, if you invoke g_application_quit() directly, you can bypass any active “holds”. I’m guessing that you are inadvertently acquiring a “hold” on the application, but where that happens isn’t obvious to me. Hope that helps a little bit!

Do you have any recommendation for viewing such data for debugging purposes? I’ve tried using valgrind and even with the distro-provided suppression files it is a needle in a haystack.

For reference, the “stack” I’m creating is just the stack.ui in the demos, but I am including it as a string rather than from a file in order to have everything visible in one source file for demonstrating this problem.

I’ve compiled and run your application, and I’m afraid I can’t reproduce the behaviour you describe. Since I don’t see any errors in your code, I’m not sure what more I can do myself, sorry.

Thank you. I’ll maybe compile it against some more recent libs (other than the ones my distro has supplied).

The behavior only occurred when I quickly opened 15+ new windows. I do appreciate the input and the sanity check!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.