Re: destroying is not freeing, is it?
- From: Tristan Van Berkom <vantr touchtunes com>
- To: franciszek holop <fred pentacom sk>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: destroying is not freeing, is it?
- Date: Mon, 02 Feb 2004 10:05:34 -0500
franciszek holop wrote:
so i looked in the .h file, and saw that objects have
a destroyed bit. so i tried the way you see down there.
i would like to ask, is this a correct approach?
If you free a piece of memory, it is unsafe to use it
afterwords:
/****************************************/
gchar *string = g_strdup_printf("Hello World");
g_free(string);
if (string) g_print(string); // <-- UNSAFE !!!
/****************************************/
Probably wiser to use a free'ing line like this:
/****************************************/
string = (g_free(string), NULL);
/****************************************/
Moral of story:
you cant play with the destroy bit of a piece of non-allocated
memory, its UNSAFE (it /should/ segfault, but usualy "Hello World"
stays on the heap untill further allocations).
Now, I'm not so sure what the gtk+-1.2 allocation modal looks
like (in respect with gtk_widget_destroy), but I think that
the object isn't destroyed (free'd) untill all its references
are released (gtk_object_unref). So if you are trying to destroy;
say; a button; it may not get destroyed untill it is removed from
its parent GtkContainer or its parent GtkContainer gets destroyed
itself.
HTH,
-Tristan
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]