lakka committed 83f4daa

Updating finalizers

Comments (0)

Files changed (1)


+In normal Python, there are two methods for writing finalizers: implementing
+``__del__``, and using ``weakref.ref`` callbacks.  Generally, ``__del___`` is
+discouraged as it does not allow the object to participate in cyclic garbage
+collection and can create uncollectible garbage if not implemented properly.
+``weakref.ref`` callbacks avoid this restriction as they do not provide a real
+reference to the object.
+In Objective-C, there is no cyclic garbage collection, so all Objective-C
+objects (including subclasses from Python) are already subject to these
+restrictions.  When subclassing an Objective-C class, you may implement
+``dealloc`` or ``__del__``.  If you implement ``dealloc``, ensure that
+you call the super ``dealloc`` at the end.  If you implement both 
+``__del__`` and ``dealloc``, the order in which they are called is
+It is not currently possible to create a ``weakref.ref`` for any Objective-C
+object.  It is probably technically possible to do, but tricky, so it
+may eventually be implemented in a future version of PyObjC (especially
+if a future Objective-C runtime supports it).
+.. todo:: Document the warning given when an object is resurrected in a 
+    finalizer