Use objc_getAssociatedObject for weakrefs

Issue #5 new
Ronald Oussoren
repo owner created an issue

It might be possible to enable Python weakrefs to Objective-C objects using the associated object APIs.

Alternatively we could use the ARC weakref APIs to implement an objc.weakref type that behaves simularly to weakref.ref, but for Objective-C objects.

Comments (2)

  1. Ronald Oussoren reporter

    It is unlikely that weakref.ref can be made to work this way, at least not without serious monkey-patching of the CPython interpreter.

    Adding an objc.weakref type should be easy enough, although it won't be possible to have callbacks (or at least not efficiently) because the ARC weakref feature just doesn't have that feature.

    It could be added inefficiently by maintaining a low-level datastructure with all objc.weakref instances with callbacks and adding a timer to the main runloop that periodicly checks if there are weakrefs that need cleanup.

    Also: objc weakrefs appearently don't work with all objects, need to further investigate that.

  2. Log in to comment