gtk_widget_destroy(my_window) memory leak



Hello,

Have ever reported the memory leak of gtk_widget_destroy?
I facing the memory leak after gtk_widget_destroy (my-gtk-window).
Memory leak occurs, thogh my window does not contain any widget.

my codes is as below:
=================================================================
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h> 

GtkWidget *sub_window=NULL;

static void on_button_clicked(GtkButton *widget, gpointer data)
{
    if (sub_window)
    {
        gtk_widget_destroy(sub_window);  // there is memory leak
        sub_window=NULL;
    }
    else
    {
        sub_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 
        gtk_window_resize(GTK_WINDOW(sub_window), 280, 320); 
        gtk_widget_show_all(sub_window); 
    }
}

int main(int argc, char *argv[]) 
{ 
    GtkWidget *window;
    GtkWidget *fixed;
    GtkWidget *button;
    GdkColor color = {0, 0x0000, 0x0000, 0xFF00};

    gtk_init(&argc, &argv); 

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL); 
    gtk_window_resize(GTK_WINDOW(window), 320, 320); 
    gtk_widget_modify_bg (window, GTK_STATE_NORMAL, &color);

    fixed = gtk_fixed_new();
    gtk_container_add (GTK_CONTAINER (window), fixed);

    button = gtk_button_new_with_label("New\n/Del");
    gtk_fixed_put (GTK_FIXED (fixed), button, 280, 120);
    gtk_widget_set_usize(GTK_WIDGET(button), 40, 40);
    g_signal_connect (G_OBJECT (button), "clicked",  G_CALLBACK (on_button_clicked), (void*)0);

    gtk_widget_show_all(window); 

    gtk_main(); 
    return 0; 
}
===================================================================

Anybody help me!

Jess.



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