-1

I'm getting the following KVO NSInternalInconsistencyException

> An instance 0x61800005a610 of class portController was deallocated
> while key value observers were still registered with it. Current
> observation info: "<NSKeyValueObservationInfo 0x610000055f90> (
> <NSKeyValueObservance 0x6100000c25a0: Observer: 0x6180000c7460, Key
> path: serialPortManager.availablePorts, Options: <New: NO, Old: NO,
> Prior: NO> Context: 0x0, Property: 0x608000080d20> ")

serialPortManager, by the way, is the singleton [ORSSerialPortManager sharedSerialPortManager]. The obvious answer, of course, is to use

[portController removeObserver:observer forKeyPath:@"serialPortManager.availablePorts"];

Problem is, I don't know who Observer: 0x6180000c7460 is. The key path is set in IB (storyboard) where the content of an NSPopUpButton is bound to a viewController, keyPath self. portController.serialPortManager.availablePorts. portController has a weak reference to serialPortManager.

I have tried looking up the address of the observer in the dSYM via dwarfdump -a in the terminal, but no luck. Is this a new thing? I don't remember having these problems with bindings in the past.

EDIT: I did not make it explicit, but the address of the NSPopUpButton is not that of the observer.

EDIT 2: I have implemented @Martin Brugger's solution to Objective C:Object Deallocated while key value observers were still registered with it which is to add symbolic breakpoint for NSKVODeallocateBreak. Unfortunately, the breakpoint is never reached, but error still shows up in the console. I'm starting to think I should file a bug report.

Community
  • 1
  • 1
Elise van Looij
  • 4,162
  • 3
  • 29
  • 52

1 Answers1

1

Put the remove observer call into the dealloc method of your class.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • please read the question. The removeObserver method takes an observer as the first parameter and I don't know who the observer is. – Elise van Looij Apr 01 '15 at 13:49
  • I did read (and answer) the question, so no need to get aggressive. The observer removes itself in dealloc. Use "self". – Mundi Apr 01 '15 at 17:20
  • who is self? That is what my question comes down to. Who is self, where is this dealloc? – Elise van Looij Apr 14 '15 at 11:44
  • It is in your error message. The class is `portController` (you should really use capitalized names for classes). You simply override `dealloc`. – Mundi Apr 14 '15 at 13:30
  • You should not believe everything you read in an error message. portController is an instance of NSObject, and appears here as a property on a viewController. Hence the binding to self. portController.serialPortManager.availablePorts. – Elise van Looij Jun 17 '15 at 14:51
  • Either you override code in your "instance of NSObject", then you should know which class it is. Or you do not, then the property does nothing and you should get rid of it. – Mundi Jun 18 '15 at 00:38
  • portController (an instance of TBPortController:NSObject) manages the connections to one or more Arduino boards. To discover the USB ports, it uses ORSSerialPortManager, of the ORSSerialPort library written Andrew Madsen. portController waits on a background thread while singleton [ORSSerialPortManager sharedSerialPortManager] collects the available ports and then looks for a USB port to which an Arduino is connected. portController does not use an observer for this. It's a simple if (self.serialPortManager.availablePorts.count == 0) usleep(3000) and try again. – Elise van Looij Jun 18 '15 at 15:45