Objective-C "weak" references and Python proxies

Issue #6 new
Ronald Oussoren
repo owner created an issue

We have a longstanding problem in PyObjC when dealing with weak references in Objective-C.

One example of this is the NSOutlineView datasource: that datasource returns objects describing the outline. The outline view does not -retain these objects, but does store references.

When the returned value is a plain python object the bridge creates an autoreleased proxy object. Because that object is not -retain-ed by NSOutlineView the view ends up with a garbage pointer and that causes crashes.

There are currently two workarounds:

Store the returned Python objects in an NSMutableArray (or other

container) to ensure that there is strong reference to the proxy

Use Cocoa subclasses in the model, that also ensures that

the returned objects stay alive (due to the strong reference in the model).

Both are suboptimal.

Investigate if it is possible to ensure that the proxy object stays alive at least as long as the python object it refers to (but without introducing refcount cycles).

Comments (0)

  1. Log in to comment