freeing GTK+ memory

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

 



-----BEGIN PGP SIGNED MESSAGE-----Hash: SHA1
Hi
all GTK classes have a create function and instances may be created with g_object_new as well. How can I free the memoryof widget's I don't need anymore? Does gtk_widget_destroy do the work for me?
I've written a small application#include <gtk/gtk.h>
void quit_app(GtkWidget *widget, gpointer data){	gtk_main_quit();}
void killme(GtkButton *button, gpointer data){	gtk_widget_destroy(GTK_WIDGET(data));}
int main(int argc, char **argv){	gtk_init(&argc, &argv);
	GtkWindow *window = g_object_new(GTK_TYPE_WINDOW,			"title", "Who does call g_free?",			NULL);
	g_signal_connect(window,			"destroy",			G_CALLBACK(quit_app),			NULL);
	GtkButton *button = g_object_new(GTK_TYPE_BUTTON,			"label", "kill me", NULL);	g_signal_connect(button, "clicked", G_CALLBACK(killme), window);	gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(button));
	gtk_widget_show_all(GTK_WIDGET(window));	gtk_main();	return 0;}

When I run it with valgrind I get==11838== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 33 from 2)==11838== malloc/free: in use at exit: 407,811 bytes in 6,544 blocks.==11838== malloc/free: 42,041 allocs, 35,497 frees, 11,626,260 bytes allocated.==11838== For counts of detected errors, rerun with: -v==11838== searching for pointers to 6,544 not-freed blocks.==11838== checked 585,612 bytes.==11838====11838== LEAK SUMMARY:==11838==    definitely lost: 25,376 bytes in 893 blocks.==11838==      possibly lost: 71,496 bytes in 79 blocks.==11838==    still reachable: 310,939 bytes in 5,572 blocks.==11838==         suppressed: 0 bytes in 0 blocks.==11838== Rerun with --leak-check=full to see details of leaked memory.
6500 non-freed blocks? It seems "a lot" for me. Even a small programm like
int main(int argc, char **argv) {gtk_init(&argc, &argv);return 0;} has 619 non-free blocks. Why? Is there a function tofree this memory?
Some function tell me that I need to free the memory by myself. For example, yesterday I wrote
GtkLabel *label;PangoAttrList *attrib_list = pango_attr_list_new();
PangoAttribute *attr = pango_attr_weight_new(PANGO_WEIGHT_BOLD);pango_attr_list_insert(attrib_list, attr);
attr = pango_attr_foreground_new(21588, 4626, 50886);pango_attr_list_insert(attrib_list, attr);
label = g_object_new(GTK_TYPE_LABEL,    "label", "Select the desired drink and click the button",    "attributes", attrib_list,     NULL);
The pange documentation points to the fact that the memory reserved by pango_attr_weight_new, pango_attr_foreground_new,etc. should be freed by the user using pango_attribute_destroy, etc. What happens if I dogtk_widget_detroy(GTK_WIDGET(label))? Do I have to free the memory from pango by myself?
RegardsPablo

- --Pablo Yánez Trujillohttp://klingsor.informatik.uni-freiburg.de/My public key: http://klingsor.informatik.uni-freiburg.de/gpg/supertux.asc-----BEGIN PGP SIGNATURE-----Version: GnuPG v2.0.9 (GNU/Linux)
iEYEARECAAYFAkj3jggACgkQDzf8xo+0xRWG9ACg3WJ9y3aX12ADo27HfqGSSL7AAlUAnAlln2+4dosliB3wqk8UCnvaEmIb=1Sce-----END PGP SIGNATURE-----_______________________________________________gtk-list mailing listgtk-list@xxxxxxxxxxxxx://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux