Re: [gtk-list] Proxy objects and circular garbage



Michael Beach <mbeach@zip.com.au> writes:

> So, my question is, how do people get around/deal with this sort of
> thing in other language bindings, such as Perl, Python, Eiffel and
> Guile?

In the guile-gtk bindings, the gtk->proxy link is a weak one.  More
precisely, the pointer is stored in a place where the conservative
collector of Guile does not find it.  I think this works fine.

However, there are other situations that creates a real circle that
cannot be broken by weakening one link.  One such situation arises
with signal handlers.  When you connect a Scheme procedure as a signal
handler to a GtkObject, that connection must prevent the Scheme
procedure from being collected.  But more often than not, the Scheme
handler has the GtkObject in its environment, thus forming a circle.

This dilemma gets resolved because when you "destroy" an GtkObject,
all its signal handlers are disconnected.  "Destroying" is not at all
related to memory management, it merely makes the object unsuable, by
removing it from the Screen when it's an widget, for example.  Thus, a
positive reference count will not prevent a GtkObject from being
destroyed.

A similar circle will arise when attaching Scheme values to an
GtkObject with gtk_object_set_data/gtk_object_get_data but I don't
think that it is always the right thing to detach these datas upon a
"destroy" request.  Fortunately, Guile has other means to attach
arbitrary key/value pairs to objects and we should use these instead.



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