[Pythonmac-SIG] Using UKKQueue with PyObjC

Bob Ippolito bob at redivi.com
Tue Mar 8 22:06:38 CET 2005

On Mar 8, 2005, at 15:35, Florian Munz wrote:

> Bob Ippolito <bob at redivi.com> wrote:
>> You forgot to specify WHICH notification in Converter.. you're saying
>> "add my documentChanged: selector as an observer to... nothing".
> The object and name are None, because I want to listen to all
> notifications (just for this test, but adding a specific name doesn't
> change anyting in this example).
> However, if I instantiate the Converter class over IB everything works
> as intended, but if I delete the instance from IB and create the object
> via Converter.alloc().init() from the other class the App crashes. I 
> get
> segfaults and bus error from pdb.
> I uploaded the crash-log [1] if this is any help, but I think I am just
> doing something fundamental wrong, but I don't know how to debug this
> any further.
> [1] http://theflow.de/TestCocoa_crash.log

The crash log makes it obvious, thanks.

Not all Objective-C objects retain other objects, similar to a weakref 
in Python.  When they use a dead object, the application crashes (where 
a weakref in Python would raise an exception, because they're safer).  
In this case, your Controller object is:
(a) getting deallocated because you're not storing away a reference to 
it anywhere
(b) not getting retained by NSNotificationCenter, because notification 
centers don't retain their observers
(c) not removing itself from NSNotificationCenter on __del__, which is 

What you need to do here is:
(a) implement a __del__ that removes it as an observer or otherwise 
ensure that the Controller object is never an observer after it's dead 
(i.e. by making sure it never dies, or removing it manually before it 
goes away).
(b) make sure it's alive for the duration that you want it to receive 
notifications, by storing away a reference to it somewhere.. if you are 
just testing and you want it to never go away, do self.retain()


More information about the Pythonmac-SIG mailing list