Aaron Optimizer Digulla <[EMAIL PROTECTED]> writes:

> > - When a Python object is created, it get's added to an internally
> > maintained dictionary that maps the Gtk object to it's Python object.
> > This increments the reference count of the Python object.
> 
> Why is this neccessary ? Isn't is sufficient to believe that all
> python objects will be referenced as long as the Gtk object
> exists ?

No, it's not sufficient to believe that.  In fact, I think that's
exactly what the above dictionary is supposed to achive.

> For example, when I add a button to a window, the Python Button
> object must be added to the Python Window object (in order to be
> able to find it again).

Yes, but all other references to these objects can disappear.  For
example, I can do this in a function:

    window = GtkWindow ()
    ...
    return TRUE

Now, the only reference to the Python object is through a Gtk object
-- when the latter is destroyed, so should the former be, not before
(as is the case at the moment).  The problem is that for that to work,
the Gtk object must know which Python object it belongs to while
avoiding circularities visible to Python GC.

> > - When a python object needs to be returned to the user, it is fetched
> > from the dictionary, rather than returning a newly created object.
> >
> > - When a Gtk object is destroyed, the corresponding Python object is
> > deleted from the object dictionary, thus decrementing the reference
> > count, possibly deleting the python object.
> 
> :-/ Why are you sure that the python object *can* be deleted when the
> Gtk object is ?

He said "possibly", didn't he?  Python object will be deleted only if
its refcount drops to zero, which indeed means that it is not
referenced by anyone else and that it may safely be deleted.

> Eg. what happens if the Gtk object should be destroyed but the
> Python object is still refd somewhere else ? Or the other way round:
> What happens when I del the python object but the Gtk object is
> still used somewhere in Gtk ?

How can you "del" the Python object?  You cannot do any such thing
AFAIK.  You can call its __del__ function, but that's not the same.
For example, how do you explicitly "delete" number 3 or string "foo"?
To unsubscribe: echo "unsubscribe" | mail [EMAIL PROTECTED]

Reply via email to