Re: Proposal: gtk_object to emmit reference changed signals



On 9 Nov 1999 21:36:24 -0500, Sam O'Connor <oconnor@eiffel.com> wrote:
>I would like some kind of hook to do stuff
>when an object's reference count changes.
>I guess a signal for ref and one for unref.
>I need to be able to do stuff when the count
>goes from 1 to 2 and when it goes from 2 to 1.
>
>I am currently working on a problem that
>involves getting the GTK+ reference counting
>system to cooperate nicely with a mark & sweep
>GC in an Eiffel system.

Trying to mirror refcounts between different objects didn't work very well
for the ObjC bindings when I was doing them. I'm not quite clear on how the
Eiffel GC works - does it allow you to have an is_object_in_use() method
called? The best way seems to be to just have an Eiffel object with no
explicit refcounts on a GtkObject, and then when the 'destroy' signal on the
GtkObject fires, you mark your Eiffel object as being no longer in use. You
also have a way to turn a GtkObject into an Eiffel object
(gtk_object_[gs]et_data():).

Since the GtkObject has the final word on whether the "object" lives or
dies, and is in fact the "real" object, you shouldn't need to necessarily
have an Eiffel object around even when the GtkObject is still alive. The
Eiffel object is only used by Eiffel stuff, not by gtk+, so you should
ignore any gtk+ refcounts when determining whether the Eiffel object lives
or dies.

Another data point - What the ObjC bindings do is keep the ObjC Object alive
until the 'destroy' signal is received on the gtk+ object. If the ObjC
object is freed explicitly, the signal handler is removed and then the
GtkObject is destroyed. No reference counts either way are involved.

Besides, the gtk signal system needs to acquire & release refcounts on
objects, which would cause a nice amount of infinite recursion if your
suggestion were to be implemented.
-- Elliot
Do not meddle in the affairs of dragons,
for you are crunchy and good with ketchup. 



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