Question about garbage collection

Greg Ewing greg.ewing at canterbury.ac.nz
Tue Jan 16 20:01:49 EST 2024


On 17/01/24 4:00 am, Chris Angelico wrote:
> class Form:
>      def __init__(self):
>          self.elements = []
> 
> class Element:
>      def __init__(self, form):
>          self.form = form
>          form.elements.append(self)

If you make the reference from Element to Form a weak reference,
it won't keep the Form alive after it's been closed.

-- 
Greg


More information about the Python-list mailing list