Proxy objects and circular garbage
- From: Michael Beach <mbeach zip com au>
- To: gtk-list redhat com
- Subject: Proxy objects and circular garbage
- Date: Thu, 16 Apr 1998 02:11:06 +1000
Salutations all!
I was going to ask this question when the problem actually bit me, but
seeing everybody is talking about proxy objects in GtkPerl, I guess now
may be a good time.
Basically, the problem I perceive is that a gtk+ object must have some
kind of pointer to an object that is proxying for it, and the proxy has
to maintain a pointer to the gtk+ object, and hence contribute to its
reference count. This unfortunately yields a cycle in the data structure
ie
+--------------+
| |
gtk+ object v
^ proxy
| |
+--------------+
and because gtk+ uses a reference counting scheme, this equates to
circular garbage. That is, the proxy will always ensure that the ref
count of the gtk+ object is non-zero and so it will not be destroyed,
and the gtk+ object will always ensure that the proxy is seen as live
(in the case of a garbage collected environment) or will have a non-zero
ref count. Doesn't take much to see that this is a hassle.
One way to get around this would be to use a weak reference for either
the proxy -> gtk or the gtk -> proxy reference. Doing this for the proxy
-> gtk reference does not seem like such a hot idea, as effectively this
means that the gtk+ object can go away at any time, and the proxy will
then have nothing to proxy for. Using a weak reference for the gtk ->
proxy reference is still not so great, but is bearable. A proxy will go
away if there is no longer any reference to it other than from the gtk+
object, but we can easily create another if we need to refer to that
gtk+ object again, so that situation is for the most part tolerable. The
limitation it does place is however that the proxy must be effectively
stateless (apart from knowing which gtk+ object it is proxying for) as
the proxy may be destroyed and recreated, and hence lose any state it
had stored.
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? Or am I not thinking straight and this kind of problem never
occurrs in practice for reasons that have not occurred to me? Your
thoughts on this would be greatly appreciated.
Regards
M.Beach
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]