Re: Gtk-- refcounting question
- From: Owen Taylor <owt1 cornell edu>
- To: Tero Pulkkinen <terop students cc tut fi>
- Cc: gtk-list redhat com
- Subject: Re: Gtk-- refcounting question
- Date: 04 Mar 1998 14:45:14 -0500
Tero Pulkkinen <firstname.lastname@example.org> writes:
> Brian Alexander Martin <email@example.com> writes:
> > I've got a question about the current status of refcounting in gtk--.
> It could be better :)
> I think current situation is that the C++-parts of the gtk objects are
> not destroyed when container keeping the objects is destroyed. This is
> something that absolutely needs to be fixed. (This is why there's
> message in the web page asking people to use new instead of local
> scope for storing objects that are inserted to containers - that use
> of the objects can certainly be preserved when the refcounting is
> fixed, it might break the objects in local scopes)
> I dunno exactly how it should be solved... We'll see. Probably should
> make some way for C++ to handle all the refcounts...
If you are content to make people explicitely do reference counting
for C++ objects. (And I don't see a better way of doing it),
Then I believe there is a simple way of doing it.
When you add the "cpp" object data for a widget, do that with:
void gtk_object_set_data_full (GtkObject *object,
const gchar *key,
Then, have the GtkDestroyNotify function delete the C++ object.
If somebody does an explicit delete on an C++ object that was
was not created in C++, then everything is OK - you just remove
the "cpp" object data. However, explicit deletes on objects created
in C++ are unacceptable. So you probably should disallow them
Note that you may want to provide automatic pointers to make
all this easier - i.e.,
Gtk_Button_var button = new Gtk_Button ("Hello");
Works fine, though the C equivalent wouldn't, because a
reference count is held by Gtk_Button_var until the end
of the scope.
(Probably it would be:
typedef Gtk_Var<Gtk_Button> Gtk_Button_var;
You could get an implementation of the automatic pointer from any
CORBA ORB, e.g., MICO, if you aren't already familiar with how they
] [Thread Prev