I've managed to commit the same error twice in 3 weeks, just long enough apart 
for me to forget what I did the last time and spend an age debugging again. 

Basically in one of my property setters on an object I set up KVO on the object 
set into the property (and of course tear down KVO on the previous object if 
there was one). Much later on I find myself crashing in obj_msgSend() trying to 
send a retain to a piece of garbage. In each case the problem is that I was not 
setting the property nil in the dealloc method (which would tear down the KVO) 
so a spurious KVO hung around and was eventually triggered leading to a crash 
down the road. This is ARC on iOS by the way. 

You used to get a handy message logged to the console when an object with KVO 
registered on it was deallocated, but not in either of these two cases (and I 
can quite clearly demonstrate that the object was dealloc'ed with dangling 
KVO). Has that message been removed, or is something internal in ARC causing 
the runtime not to notice? I'm quite sure that fairly recently some code I 
still have which doesn't use ARC was emitting this message using the same 
compiler and version of Xcode. 

One learned lesson here is that I have too-quickly become used to what ARC does 
and have become a little sloppy with dealloc(), not having to release things in 
it has meant I'm not forced to think about the other things I might need to do 
there, a habit I need to get back into. 

Also, I found zombies didn't help me here, I did eventually track it down by 
working through a whole mess of malloc_debug (and looking at the then-obvious 
stack trace). 




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to