Re: tooltips and refcounts



On Mon, 10 Aug 1998, George wrote:

> On Mon, Aug 10, 1998 at 11:59:42AM +0200, Tim Janik wrote:
> > > this tooltip thing actually makes things complicated ... in the panel for
> > > example I have a lot of widgets for which I set tooltips ...
> > > 
> > > I have put a "set tooltip to NULL function" in the applet clean up code ...
> > > however that code isn't allways called ... for example when I remove a panel
> > > (a drawer) ... I rely on getting the destroy signal from the applet ...
> > > which however never comes .. as when the widget is unparented it still has
> > > a refcount hanging around .. and the widget will stay and eat up ram (plus
> > > I can't do cleanup) .... manually going in and setting all tooltips to NULL
> > > seems like a VERY UGLY solution ...
> > 
> > you most probably don't do the right thing in your code then.
> > you either just want to reparent a widget from one window to another (and
> > in this case there is no reason for gtk to implicitely remove the actual tip
> > you have set for this widget), or you want to destroy it, in which case the
> > tip will be removed. but either way, if you want widgets to be destroyed,
> > call gtk_widget_destroy (widget) on 'em, but don't unparent or remove
> > a widget and then wait for its destruction.
> 
> well the thing is ... without the tips .. everything works perfectly just
> by destroying the parent ... all it's widgets get killed as well ...

tips shouldn't change taht (and don't actually, as far as my experience goes).

> I don't remove the tip when it's reparented .. but before it's destroyed
> ...... right now I  put in code that traps the destroy on the panel widget
> and sets tooltips to null on all it's widgets ... but that seems very
> ugly to me ...

the tooltips catch ::destroy signals of widgets and remove the tooltips data
portion in such cases (including a decrement of the widgets reference count).
so i don't get what exactly your problem is...

> I have also just realized I have some code at work which has some major
> memory leaks due to this .. since I don't keep around pointers to the
> widgets that I set tooltips on .. I only destroy their parent (those are
> dynamically added and removed) ... so now I need to either parse the widget
> tree and remove all tips before that .. or store pointers to the widgets ...
> both of which would be fairly ugly

why would you want to do this? tooltips care of widget destruction themselves,
if they keep a reference count on the widget until then or not, that you
really shouldn't care about (the actuall *value* of
GTK_OBJECT(widget)->ref_count is actually nobody's business outside of gtk).

> I would have thought that the philosophy would be more owner->slave ...

if you want to think of it this way, the tooltips object "owns" the widget
in the sense that it keeps a reference to it within it's widget list.

> the tip doesn't gain anything by keeping the widget alive for itself ...

there is no code that implements such an intend.

> I would have thought it would be the other way around .. the widget keeping
> a refcount for the tip ... since we care about the tip staying around as
> long as the widget does .. not the other way around

this is not really a matter of keeping someone alive. if the widget is
destroyed, its associated tip will as well. also, if the tooltips is
destroyed, all associated tips will be destroyed too. the reference
counts are held so that neccessary upcoming pointer dereferences will
not end in nowhere.

> I don't think the tip should be removed when reparented ... but I think it
> shouldn't raise the refcount ... it should just "autoclean" itself when the
> widget is gone ...

i still don't get why you bother about the refcount of a widget. the widget
will be destroyed with its parent, regardless of its refcount value.

> the entire point of refcounts IS that if you have a reference to something
> you want that something to stay around .. however a tooltip doesn't need
> that something to stay around ... it should be tied to that something and
> die when the widget dies ...

the "something" you are talking about is actually just the memory allocated by
the widget's structure, and the tooltips care about proper in-time unref()
calls.

> > static void
> > widget_remove_tip (GtkWidget   *widget)
> > {
> >   GtkTooltipsData *tdata;
> >   
> >   tdata = gtk_tooltips_data_get (widget);
> >   if (tdata)
> >   {
> >     /* catch the case where a widget gets its parent removed */
> >     if (widget->parent == NULL)
> >       gtk_tooltips_set_tip (tdata->tooltips, widget, NULL, NULL);
> >   }
> > }
> > 
> > [when you set the tip for a widget you do:]
> > 
> >   gtk_tooltips_set_tip (tooltip, widget, "I'm nice", "Kick me!");
> >   gtk_signal_connect (GTK_OBJECT (widget),
> >                       "parent_set",
> >                       widget_remove_tip,
> >                       NULL);
> 
> that won't work right ... I don't want to kill the tip when the widget
> has no parent .. that would kill it during reparent ... right now I have

sorry, i got the impression that removing the tip on reparentation was
your actuall intend.

> to write code that tracks when the widget should be destroyed and hunt
> those down ... I still don't see why a refcount for tooltips is justified

[...]

> 
> George
> 

---
ciaoTJ



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