we leak ...



Hi,

attached is a simple test application that calls gtk_label_set_text()
from a timeout. top and memprof show that the application (linked
against gtk+-1.3.8 running under X11) leaks memory like hell. I found
a leak in pango (see my previous mail), but it's obviously not the
only source of leakage. Perhaps posting the test application here
helps to track the problem down.


Salut, Sven

#include <stdio.h>
#include <gtk/gtk.h>

GtkWidget *label;
guint count, timeout_id = 0;


gboolean set_text (gpointer foo)
{
  char buf[32];
  
  sprintf(buf, "%03d", ++count);
  gtk_label_set_text (GTK_LABEL(label), buf);

  return TRUE;
}          


void click_callback (GtkWidget *widget,
                     gpointer   data)
{
    if (timeout_id)
      {
        g_source_remove(timeout_id);
        timeout_id = 0;
      }
    else
      {
        timeout_id = g_timeout_add (10, set_text, 0);
      }
}


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

int main (int   argc,
          char *argv[])
{
    GtkWidget *window;
    GtkWidget *button;
    GtkWidget *vbox;
    
    gtk_init(&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

    label = gtk_label_new ("foo");
    count = 0;

    vbox = gtk_hbox_new (FALSE, 0);
    
    gtk_signal_connect (GTK_OBJECT (window), "destroy",
                        GTK_SIGNAL_FUNC (destroy), NULL);
    
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    
    button = gtk_button_new_with_label ("Leak!");
    
    gtk_signal_connect (GTK_OBJECT (button), "clicked",
                        GTK_SIGNAL_FUNC (click_callback), NULL);
    
    gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 5);
    gtk_box_pack_end (GTK_BOX (vbox), button, TRUE, TRUE, 5);
    
    gtk_container_add (GTK_CONTAINER (window), vbox);
    
    gtk_widget_show (label);
    gtk_widget_show (button);
    gtk_widget_show (vbox);
    gtk_widget_show (window);
    gtk_main ();
    
    return(0);
}


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