Re: [Pyobjc-dev] KV Observers caused Abort Trap (or: when to remove them)
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2005-04-06 07:52:48
|
On Apr 6, 2005, at 12:49 AM, Clive Jevons wrote: > On 6 Apr 2005, at 09:43, Bob Ippolito wrote: > >> >> On Apr 6, 2005, at 12:25 AM, Clive Jevons wrote: >> >>> In one of the apps I'm writing I use KVO in order to track when a >>> property of a data object is changed so that I can mark it dirty. >>> That part works really nicely - in the init() method of the object, >>> I attach an observer (itself) for each property which is stored in >>> the DB. Everything worked fine until I re-loaded the data, or >>> deleted an object. Then the whole thing would crash out without >>> giving any hint or sign as to why. As the KVO was the only thing I'd >>> changed, I knew it had to be that. After a quick think, I figured it >>> was because I hadn't detached them before releasing all references >>> to the object in python, and that there were probably invalid >>> pointer or references hanging around in the Objective-C part >>> responsible for KVO. Once I added calls to >>> removeObserver_forKeyPath_ in all the appropriate places everything >>> was fine again. >>> >>> I *did* try to do the removing of the observers in the dealloc >>> (which told me I wasn't to use that method) and the __del__ ... but >>> the latter wasn't called before the app bombed out with an 'Abort >>> Trap'. >>> >>> The solution I currently have works, but I find the code quite >>> untidy - on the whole, the reason I love Python is that it enables >>> me to express a solution to a problem without loads of technical >>> grunt work - like memory management - so having to intersperse KVO >>> cleanup code with my business code is really going against the grain >>> :( ... can anyone suggest a cleaner solution to this? >> >> If you post a simple runnable example that breaks, I'll look into it. >> > Can I post TGZs to the list (I'll probably have to include a nib for > the example) or do I have to post it to a web site and then post the > link to the list? > I don't believe the list would like tgz files, but you can either post them somewhere or send it to me off-list. If you post them somewhere, someone else might have a chance to answer your question, so that's definitely the better option -- but either works. -bob |