Re: destroying an unparented widget



ping. Since the message below has not drawn an answer to date,
perhaps I should add: I'm well aware that reports of memory leaks
in the GTK stack are often spurious, and I'm using
G_SLICE="always-malloc", and mostly my GTK widget usage shows no
leaks via valgrind, but I'm still puzzled by the case of a widget
which is allocated "off-screen" and then nominally destroyed, but
which then shows up in valgrind as leaking.

On Thu, 5 May 2011, Allin Cottrell wrote:

There's one thing I've never quite understood: the correct
mechanism for destroying a gtk widget that is never parented or
shown.

The context is that I'm creating a temporary widget with
gtk_label_new(), just for the purpose of getting hold of its
PangoContext so I can figure something out about the font in use
(whether it supports the UTF-8 minus sign, 0x2212). Once I've got
that info I'm using gtk_widget_destroy on the label. And valgrind
is showing me a leak, which I take to mean that I haven't managed
to destroy the widget. If I try using g_object_unref() instead I
get an error message from GTK saying I can't do that on an object
which has only a floating reference.

Would the correct sequence be

label = gtk_label_new("");
g_object_ref_sink(G_OBJECT(label));
/* do pango stuff */
g_object_unref(G_OBJECT(label));

? And if so, is there an equivalent in GLib < 2.10? Thanks.

-- 
Allin Cottrell
Department of Economics
Wake Forest University




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