From 69b1611e5969a945d4d0dd4f3dafda25d892c834 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 1 Nov 2004 19:19:06 +0000 Subject: [PATCH] Add a "ref and sink" question. (#156865, Philip Langdale, text based on a 2004-11-01 Matthias Clasen * gtk/question_index.sgml: Add a "ref and sink" question. (#156865, Philip Langdale, text based on a comment by Owen Taylor) * gtk/tmpl/gtkrc.sgml: Document im_module_file and settings assignments as toplevel statements. --- docs/reference/ChangeLog | 6 +++- docs/reference/gtk/question_index.sgml | 46 ++++++++++++++++++++++++-- docs/reference/gtk/tmpl/gtkrc.sgml | 2 +- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index 7cb35eba9d..37add64c52 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -4,9 +4,13 @@ Mon Nov 1 13:37:31 2004 Jonathan Blandford 2004-11-01 Matthias Clasen + * gtk/question_index.sgml: Add a "ref and sink" question. + (#156865, Philip Langdale, text based on a comment by Owen + Taylor) + * gtk/tmpl/gtkrc.sgml: Document im_module_file and settings assignments as toplevel statements. - + 2004-10-31 Matthias Clasen * gtk/windows.sgml: s/PRETEND_WIN9X/G_WIN32_PRETEND_WIN9X/. diff --git a/docs/reference/gtk/question_index.sgml b/docs/reference/gtk/question_index.sgml index 9c027c948f..d062c4e36c 100644 --- a/docs/reference/gtk/question_index.sgml +++ b/docs/reference/gtk/question_index.sgml @@ -116,9 +116,51 @@ url="http://bugzilla.gnome.org">http://bugzilla.gnome.org.) - + + + +Why does my program leak memory, if I destroy a widget immediately +after creating it ? + + + + + +If GtkFoo isn't a toplevel window, then + + foo = gtk_foo_new (); + gtk_widget_destroy (foo); + +is a memory leak, because no one assumed the initial floating +reference. If you are using a widget and you aren't immediately +packing it into a container, then you probably want standard +reference counting, not floating reference counting. + + + +To to get this, you must acquire a reference to the widget and drop the floating +reference (ref and sink in GTK+ parlance) after creating it: + + foo = gtk_foo_new (); + g_object_ref (foo); + gtk_object_sink (GTK_OBJECT (foo)); + +When you want to get rid of the widget, you must call gtk_widget_destroy() +to break any external connections to the widget before dropping your +reference: + + gtk_widget_destroy (foo); + g_object_unref (foo); + +When you immediately add a widget to a container, it takes care of +assuming the initial floating reference and you don't have to worry +about reference counting at all ... just call gtk_widget_destroy() +to get rid of the widget. + + + @@ -483,7 +525,7 @@ to the GNOME 2.0 platform. -Why are types not registered if I use their GTK_TYPE_BLAH; macro ? +Why are types not registered if I use their GTK_TYPE_BLAH macro ? diff --git a/docs/reference/gtk/tmpl/gtkrc.sgml b/docs/reference/gtk/tmpl/gtkrc.sgml index 55d2d1b597..d09525ff43 100644 --- a/docs/reference/gtk/tmpl/gtkrc.sgml +++ b/docs/reference/gtk/tmpl/gtkrc.sgml @@ -219,7 +219,7 @@ The possible toplevel declarations are: - setting = value + setting = value Specifies a value for a setting. Note that settings in RC files are overwritten by system-wide settings which are managed by