memory leak when destroying widgets

Hello list
I have this short program that's leaking memory (according to top). Could someone tell me what I'm doing wrong?
The program simply creates, packs and shows 100 gtk_entries and then destroys them at 400 ms intervals
I appreciate any help you can give
P.-S. I didn't know which list to send it to, so I sent it to both. If someone could tell me which of the two lists is more appropriate, I'll stop bothering the other one

...and now, the program:

/* gcc -Wall -g test.c -o test2 `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0` */
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>

GtkWidget *vbox;
GtkWidget *entry;

guint test_function(gpointer data){
  GList *iter;
  iter = gtk_container_get_children (GTK_CONTAINER (vbox));
    GtkWidget *child;
    child = iter->data;
    iter  = iter->next;
  int i;
  for( i = 0 ; i < 100 ; i++){
    entry = gtk_entry_new ();
    gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0);
    gtk_widget_show (entry);
  return 1;

int main( int   argc,
          char *argv[] )

    GtkWidget *window;
    gtk_init (&argc, &argv);

    /* create a new window */
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request (GTK_WIDGET (window), 200, 100);
    gtk_window_set_title (GTK_WINDOW (window), "GTK Entry");
    g_signal_connect (G_OBJECT (window), "destroy",
                      G_CALLBACK (gtk_main_quit), NULL);
    g_signal_connect_swapped (G_OBJECT (window), "delete_event",
                              G_CALLBACK (gtk_widget_destroy),
                              G_OBJECT (window));

    vbox = gtk_vbox_new (FALSE, 0);
    gtk_container_add (GTK_CONTAINER (window), vbox);
    gtk_widget_show (vbox);

    g_timeout_add(400,(GSourceFunc) test_function,0);
    gtk_widget_show (window);


    return 0;

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]