Many objects don't report KVO leaks
| Originator: | me | ||
| Number: | rdar://10533738 | Date Originated: | 06-Dec-2011 03:57 AM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Serious Bug | Reproducible: | Always |
06-Dec-2011 03:57 AM Jonathon Mah: 'main.m' was successfully uploaded 06-Dec-2011 03:57 AM Jonathon Mah: I had a random crasher in my app that I eventually determined was due to an unbalanced key-value observation of an NSArrayController. I mistakenly believed that my code was correct (or rather, figured that "the view controller's autounbinder must be taking care of things") because I never received the leaked KVO warning: "An instance 0x10f617c30 of class NSObject was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info..." I made a trivial tool which verified that this message is printed for classes using NSObject's -addObserver:... mechanism. Unfortunately this doesn't include NSDictionary, and particularly NSController and subclasses, which is explicitly designed to have a multitude of observers. You can compile the attached code with: % clang -fobjc-arc -framework Cocoa main.m -o ObserveWarningTest % ./ObserveWarningTest 2011-12-06 03:50:35.804 ObserveWarningTest[44968:707] -------- 2011-12-06 03:50:35.807 ObserveWarningTest[44968:707] Observing <NSObject 0x10f617c30> 2011-12-06 03:50:35.817 ObserveWarningTest[44968:707] An instance 0x10f617c30 of class NSObject was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info: <NSKeyValueObservationInfo 0x7f8970d02aa0> ( <NSKeyValueObservance 0x7f8970d02750: Observer: 0x10f617c20, Key path: self, Options: <New: NO, Old: NO, Prior: NO> Context: 0x0, Property: 0x7f8970d01ed0> ) 2011-12-06 03:50:35.818 ObserveWarningTest[44968:707] -------- 2011-12-06 03:50:35.819 ObserveWarningTest[44968:707] Observing <__NSCFDictionary 0x10f618b10> 2011-12-06 03:50:35.819 ObserveWarningTest[44968:707] -------- 2011-12-06 03:50:35.820 ObserveWarningTest[44968:707] Observing <NSArrayController 0x10f619020> Expected output: A KVO warning after each of the three "Observing" lines.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!