Re: [gtk-list] Freeing memory that was used by GTK
- From: Tim Janik <timj gtk org>
- To: David Allen <opop erols com>
- cc: GTK+ List <gtk-list redhat com>
- Subject: Re: [gtk-list] Freeing memory that was used by GTK
- Date: Tue, 22 Jun 1999 05:44:25 +0200 (CEST)
On Mon, 21 Jun 1999, David Allen wrote:
>
> What is the real advantage to using g_free over free? For normal variables,
> say, allocated with calloc, how does it help?
g_free() is the complement to free memory allocated through g_malloc(),
g_malloc0(), g_new(), g_new0(), g_renew(), g_realloc() or one of the
various g_str*() functions that return newly allocated strings. virtually
all functions throughout gtk and gnome that return newly allocated memory
also require usage of g_free() to release the memory. in practice you
don't want to use plain system's malloc(), calloc() etc. variants anymore
once you've started out to use glib (or gtk/gnome), especially since you
have not to intermix malloc()/free() with g_malloc()/g_free() for the same
memory areas, as GLib might not only return memory allocated through the
system's memory allocators but can also reserve extra space for debugging
information (or *could* do extra padding and do allocations out of certain
GLib internal pools, though it doesn't do something like that
currently).
> And how would you go about freeing memory that has your windows, frames,
> widgets, and so on? You can't free them after they've been set up and
> displayed, but you still have to free that memory in order to prevent a leak,
> right? Does gtk_main_quit do that stuff for you?
usually, the only thing you need to do is call gtk_widget_destroy (window)
explicitely, which will care about destructing all child widgets contained
in that window. widget destruction will also automatically free all memory
associated with a widget.
---
ciaoTJ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]