If this issue has been posted before, I can't find it.
I'm attempting to allocate and initialize an instance of NSString in the initialization method of a subclass of NSOperation (for use with NSOperationQueue). The NSString pointer is an ivar (not a property).
The program crashes with "EXC_BAD_ACCESS (code=EXC_I386_GPFLT)".
To isolate the problem, I've separated the alloc and init functions. The main thread is crashing on:
m_myString = [NSString alloc];
The code is in an "if" block:
if (someCondition)
{
m_myString = [NSString alloc];
m_myString = [m_myString initWithCString:aCharPointer encoding:NSASCIIStringEncoding];
}
else
{
m_myString = [NSString alloc];
m_myString = [m_myString initWitCString:aDifferentCharPointer encoding:NSASCIIStringEncoding];
}
Examining the thread shows that it's crashing on objc_release. I don't understand why release would be called on an object in the allocation method, but that seems to be the case...
It's worth mentioning that I successfully alloc and init another instance variable NSString in the same method before the if block.
Has anyone else run into this before, and if so, how'd you solve it?
I'd be glad to give more info upon request.