After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 91410 - Gtk::Menu: non-top-level top-level window.
Gtk::Menu: non-top-level top-level window.
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: general
2.0
Other Solaris
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2002-08-22 12:59 UTC by Michael v. Szombathely
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
the test case as described (700 bytes, text/plain)
2002-08-22 13:00 UTC, Michael v. Szombathely
Details
the test case with gtk+ (not gtkmm) (1.42 KB, text/plain)
2002-08-23 12:54 UTC, Michael v. Szombathely
Details
test case in gtk+ with extra output (1.51 KB, text/plain)
2002-08-23 13:03 UTC, Michael v. Szombathely
Details
test case with gtk+ showimg top_level creation (1.53 KB, text/plain)
2002-08-23 20:36 UTC, Michael v. Szombathely
Details
test_gtk.c (741 bytes, text/plain)
2002-10-02 17:40 UTC, Murray Cumming
Details
test_gtkmm.cc (612 bytes, text/plain)
2002-10-02 17:41 UTC, Murray Cumming
Details

Description Michael v. Szombathely 2002-08-22 12:59:38 UTC
Detected by purify, we think that Gtk::Menu objects are not properly
registered. It occurs as a GtkWindow.

As an aftereffect we see for instance that Gtk::Window::list_toplevels
produces a memory leak with Gtk::Menu objects, because
gtk_window_list_toplevels returns an object which is not associated to any
C++ wrapper object. This situation is misinterpreted and
Window_Class::wrap_new ist called, although the object is not a toplevel
window and has to be managed.
Comment 1 Michael v. Szombathely 2002-08-22 13:00:58 UTC
Created attachment 10643 [details]
the test case as described
Comment 2 Murray Cumming 2002-08-22 17:29:37 UTC
Is this 2 issues? If so, please submit 2 bugs. I don't understand the
first paragraph, particularly "occurs as a GtkWindow."
Comment 3 Michael v. Szombathely 2002-08-22 19:48:14 UTC
No, at the moment it's only one issue, which we came up during purify
tests.

"occurs as a GtkWindow" refers to the sample program, which show
GtkWindow instead of gtkmm__GtkWindow or the given name.
Comment 4 Murray Cumming 2002-08-23 08:02:22 UTC
I don't see what this proves, or what you are trying to prove.

I don't understand why 2 top-level windows  are returned by
get_top_levels(). And I don't understand why _any_ top-level windows
exist before you have called show() on your ExampleWindow. You could use 
G_OBJECT_TYPE_NAME(G_OBJECT(cppWidget.gobj())) to get the real GTK+ type.

It does seem wrong that get_top_levels() returns a Window that is not
top-level, but I would first like to know whether that happens with
normal GTK+ code. It is not unusual to have a non "gtkmm__" widget -
that's why we have wrap(), though it should not leak.
Comment 5 Michael v. Szombathely 2002-08-23 12:54:19 UTC
Created attachment 10669 [details]
the test case with gtk+ (not gtkmm)
Comment 6 Michael v. Szombathely 2002-08-23 13:03:44 UTC
Created attachment 10671 [details]
test case in gtk+ with extra output
Comment 7 Michael v. Szombathely 2002-08-23 13:14:24 UTC
The latest gtk+ example shows that the instantion of a GtkMenu object
obviously also creates automatically a (surrounding) toplevel window.

This seems to be the reason for the confusion we see in
Gtk::Window::top_level, when it detects toplevel windows which are not
C++ wrapped.

BTW: All toplevel windows are contained in the toplevel list after
their creation. This has nothing to do with show().
Comment 8 Michael v. Szombathely 2002-08-23 20:36:19 UTC
Created attachment 10684 [details]
test case with gtk+ showimg top_level creation
Comment 9 Michael v. Szombathely 2002-08-23 20:46:20 UTC
We have looked in the GtkMenu initialization code (gtk_menu_init() in
gtkmenu.c) and indeed it creates an additioon top_level. The latest
form of the sample code proves that the unwrap toplevel comes from the
menu object.

Now that we know where these additional toplevel windows come from, we
need to find a way to distinguish them from normal C++ wrapped
toplevel windows. The actual handling procuces memory leaks, because
an unrelated toplevel window gets wrapped automatically but is not
freed at the end.
Comment 10 Murray Cumming 2002-08-24 13:33:37 UTC
It is strange that get_is_toplevel() is true for both windows in the
GTK+ examples, but not he gtkmm example.
Comment 11 Murray Cumming 2002-08-28 11:06:56 UTC
I'd like to fix this properly, but is it a memory leak if you don't
call list_toplevels()?
Comment 12 Michael v. Szombathely 2002-08-28 20:13:41 UTC
No, the memory leak is introduced by calling Window_Class::wrap_new()
for an unrelated gtk+ object, which occured during the list iteration
in toplevel_window().

Here the purify output:
         PLK: 36 bytes potentially leaked at 0x12ef70
         This memory was allocated from:
               malloc         [rtlib.o]
               c2n6Fi_Pv___1  [libCrun.so.1]
               void*operator new(unsigned) [rtlib.o]
               Glib::ObjectBase*Gtk::Window_Class::wrap_new(_GObject*)
[window.cc:487]
                  
                  Glib::ObjectBase* Window_Class::wrap_new(GObject* o)
                  {
               =>   return new Window((GtkWindow*)(o)); //top-level
windows can not be manage()ed.
                  
                  }
                  
              
Glib::ObjectBase*__unnamed_kJQAKcVNb9wkv::create_new_wrapper(_GObject*)
[wrap.cc:71]
                      if(const gpointer idx = g_type_get_qdata(type,
Glib::quark_))
                      {
                        const Glib::WrapNewFunction func =
(*wrap_func_table)[GPOINTER_TO_UINT(idx)];
               =>       return (*func)(object);
                      }
                    }
                  
               Glib::ObjectBase*Glib::wrap_auto(_GObject*,bool)
[wrap.cc:138]
                    if(!pCppObject)
                    {
                      // There's not already a wrapper: generate a new
C++ instance.
               =>     pCppObject = create_new_wrapper(object);
                  
                      if(!pCppObject)
                      {
Comment 13 Murray Cumming 2002-08-29 09:47:58 UTC
So this isn't a very high priority because that method isn't used very
much.
Comment 14 Murray Cumming 2002-09-17 07:55:21 UTC
Is this bug still a bug? I am confused when reading the previous
discussion, and I don't know how to interpert the output of the test
program.
Comment 15 Murray Cumming 2002-09-23 10:50:26 UTC
Please respond.
Comment 16 Murray Cumming 2002-09-27 07:41:34 UTC
Please respond.
Comment 17 Murray Cumming 2002-10-02 17:37:49 UTC
These examples don't prove any memory leak. And purify isn't avaiable
for us to use. Maybe you could play with valgrind instead.

But there is the question of why list_top_levels() is returning a
non-top-level window.

I have added 2 new test cases - test_gtk.c and test_gtkmm.cc. They do
the same thing, with GTK+ and gtkmm. The gtkmm one returns false from
is_top_level(). That's the problem that we need to solve first.
Comment 18 Murray Cumming 2002-10-02 17:40:16 UTC
Created attachment 11361 [details]
test_gtk.c
Comment 19 Murray Cumming 2002-10-02 17:41:12 UTC
Created attachment 11362 [details]
test_gtkmm.cc
Comment 20 Murray Cumming 2002-11-10 22:23:52 UTC
This might be connected to the general bug described in #97729
Comment 21 Murray Cumming 2003-01-06 22:52:06 UTC
No, it's not.
Comment 22 Murray Cumming 2003-05-12 13:24:06 UTC
I noticed recently that attempting to add a new GtkMenu to a container
generates a warning because GtkMenu is already in a GtkWindow. It
really is that simple. Maybe we can add a special "delete
get_parent()" to the Gtk::Menu destructor.
Comment 23 Murray Cumming 2003-07-23 09:15:32 UTC
This seems to be fixed by the Glib::wrap() leak fix in gtkmm 2.2.5.
Please confirm and reopen if you disagree.