Re: [gtk-list] memory maintence in gtk
- From: Havoc Pennington <rhpennin midway uchicago edu>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] memory maintence in gtk
- Date: Thu, 29 Oct 1998 23:16:28 -0600 (CST)
On Thu, 29 Oct 1998, Todd Gureckis wrote:
> is it necessary/customary to free all the memory allocated by the creation
> of the window once it is closed... for example running free() on all
> the GtkWidget pointers in the dialog window?
>
Using g_free() instead of gtk_widget_destroy will create huge memory
leaks and probably segfault too.
> Is there a built in way to do this in gtk? This is a kind of un-informed
> observation, but when i create a dialog, then later gtk_widget_destroy()
> the dialog, the memory size of my application does not shrink when I list
> it in top.
Some detail of your system's memory management or top, not because memory
wasn't released. Or it could be Gtk's GMemChunk stuff; the memory wasn't
necessarily returned to the system, it may have been recycled in other
GtkObjects. I haven't looked at this source code. In any case rest assured
gtk_widget_destroy does the right thing.
> I wasn't sure if it would be better to save the memory,
> and dynamically allocate the whole dialog window, or leave it in memory,
> so cpu is saved the next time the dialog window is created.
>
The usual thing is to create the dialog each time, and destroy it when you
close it.
If the dialog is expensive to create though, and there's a noticeable
pause or CPU use, you can keep it around all the time. Do something like
this:
void create_dialog()
{
static GtkWidget* dialog = NULL;
if (dialog == NULL) {
dialog = gtk_dialog_new();
/* do other creation */
}
gtk_widget_show(dialog);
}
When the user closes the dialog (by clicking a button, or when you get
delete_event - be sure to handle delete_event), you gtk_widget_hide() and
it will go away until you show it again by re-calling create_dialog().
There are variations on the theme, but you get the idea. Basically a
space/time tradeoff.
Havoc
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]