On 2024-01-17 3:01 AM, Greg Ewing via Python-list wrote:
On 17/01/24 1:01 am, Frank Millman wrote:
I sometimes need to keep a reference from a transient object to a more
permanent structure in my app. To save myself the extra step of
removing all these references when the transient object is deleted, I
make them weak references.
I don't see how weak references help here at all. If the transient
object goes away, all references from it to the permanent objects also
go away.
A weak reference would only be of use if the reference went the other
way, i.e. from the permanent object to the transient object.
You are right. I got my description above back-to-front. It is a pub/sub
scenario. A transient object makes a request to the permanent object to
be notified of any changes. The permanent object stores a reference to
the transient object and executes a callback on each change. When the
transient object goes away, the reference must be removed.
Frank
--
https://mail.python.org/mailman/listinfo/python-list