Strange Objects (NSCFType, etc.) Indicate Memory Management Bugs.

Strange Objects (NSCFType, etc.) Indicate Memory Management Bugs.

Any errors involving NSCFType or some class you have never heard of (eg ”*** -[NSCFType count]: selector not recognized “) are indicators of a memory management bug. Most likely an object is getting released too soon. The freed memory is then re-allocated for a new object, say an NSCFType. The pointer to the over-released object, obj, has not changed, but is now pointing to a NSCFType, which receives any messages sent to obj (and chokes on most of them).

NSCFType is not documented anywhere by Apple. As near as I can tell, it’s some deep-dark part of Core Foundation, but whatever it really is, it’s clearly not meant to venture out of it’s deep-dark lair. So seeing it means something is very wrong.

Any “selector not recognized” message may also be the result of an early-release. I have had cases where over-released memory was reallocated as anNSString, or other ubiquitous class. However, the vast majority of my “selector not recognized” issues were caused by explicitly sending the wrong message to an object (invoking count on an NSString for example).

EDITED TO ADD: In addition to NSCFType I have also seen memory bee recycled as NSExtraMIData.

Original publish: