GtkWindow subclassing problem

From: Simon <SimonLanzmich_at_gmx.de>
Date: Thu, 04 Jan 2007 18:15:06 +0100

Hi list

I'm not sure whether the the problem i have is because of my Gob / Gtk+
"skills", GOB or Gtk, but it is as follows (a reduced example):

I subclassed GtkWindow, created some child widgets in the init method
and the show the window. All works well, the window shows and the
widgets get destroyed when I close the window. However, Valgrind tells
me that the program leaks a lot of memory.

I'm doing this on an x86_64 system running Fedora Core 6.
What do you think about this? If I did something terribly wrong, please
tell me.

Simon

Here, the files:

*** *** *** *** *** test-window.gob *** *** *** *** ***

requires 2.0.0

%h{
#include <gtk/gtk.h>
%}

%{
void
quit (GtkWidget *widget, gpointer data)
{
    gtk_main_quit ();
}

void
bla (gpointer data, GObject *where_the_object_was)
{
    printf ("finalized %s\n", (char *) data);
}

%}

class Test:Window from Gtk:Window {

    init (self)
    {
        GtkWidget *vbox, *sw, *statusbar;

        g_signal_connect (G_OBJECT (self), "destroy", G_CALLBACK (quit),
NULL);

        vbox = gtk_vbox_new (FALSE, 0);
        gtk_container_add (GTK_CONTAINER (self), vbox);

        sw = gtk_scrolled_window_new (NULL, NULL);
        gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (sw),
                            TRUE, TRUE, 0);

        statusbar = gtk_statusbar_new ();
        gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (statusbar),
                            FALSE, FALSE, 0);

        g_object_weak_ref (G_OBJECT (self), (GWeakNotify) bla, "1");
        g_object_weak_ref (G_OBJECT (vbox), (GWeakNotify) bla, "2");
        g_object_weak_ref (G_OBJECT (sw), (GWeakNotify) bla, "3");
        g_object_weak_ref (G_OBJECT (statusbar), (GWeakNotify) bla,
"4");

        return;
    }

    public GtkWidget *
    new (void)
    {
        return (GtkWidget *) GET_NEW;
    }
}

*** *** *** *** *** main.c *** *** *** *** ***

#include "test-window.h"

int
main (int argc, char **argv)
{
    gtk_init (&argc, &argv);

    TestWindow *win = TEST_WINDOW (test_window_new ());

    gtk_widget_show_all (GTK_WIDGET (win));
    
    gtk_main ();

    return 0;
}

*** *** *** *** *** program output *** *** *** *** ***

[simon_at_simon mytest]$ ./src/mytest
finalized 3
finalized 4
finalized 2
finalized 1

*** *** *** valgrind output (the end of it) *** *** ***

==10723== LEAK SUMMARY:
==10723== definitely lost: 10,330 bytes in 40 blocks.
==10723== indirectly lost: 13,824 bytes in 432 blocks.
==10723== possibly lost: 1,600 bytes in 20 blocks.
==10723== still reachable: 1,274,396 bytes in 8,567 blocks.
==10723== suppressed: 0 bytes in 0 blocks.
==10723== Reachable blocks (those to which a pointer was found) are not
shown.
==10723== To see them, rerun with: --show-reachable=yes
Received on Thu Jan 04 2007 - 17:24:02 CST

This archive was generated by hypermail 2.2.0 : Sun Apr 17 2011 - 21:05:02 CDT