I have a class that is derived from NSURLConnection. Curiously, description and dealloc fail when directed to the NSURLConnection (even though the actual data transfer operation succeeds).
Here is the init method of my class:
-(id) init {
self = [super init];
NSLog(@"%s -- self description is %@", __PRETTY_FUNCTION__, [self description]);
NSLog(@"%s -- super description is %@", __PRETTY_FUNCTION__, [super description]);
return self;
}
Here is the log output from executing this code (I implemented description for my class):
2011-08-24 10:41:40.493 SleepyHead[77578:207] -[BinaryExchange init] -- self description is <BinaryExchange>
(gdb) continue
Program received signal: “EXC_BAD_ACCESS”.
When this happens the debugger is stopped on the [super description] line, and in the call to NSURLConnection description.
What the heck is going on?
(I tried allocating and not initing another copy of the class before this one, on the off-chance that there was a piece of bogus heap getting used, but I still get the same failure.)
Added:
Even this sequence fails:
NSURLConnection* dummy = [[NSURLConnection alloc] init];
NSLog(@"%s -- dummy NSURLConnection description is %@", __PRETTY_FUNCTION__, [dummy description]);
If there is a crash, there is a backtrace. Post it.
Odd crash, though.
[super description]is pretty close to nonsense. Thedescriptionmethod is not intended to ever be used in a production environment; is a development-only method.Did you override
descriptionin your subclass, perchance?Also allocating and not initing another doesn’t really do anything. It may not even allocate anything. Most class clusters and many other classes (as implementation details) will return a singleton on
allocand it isn’t until the initialization that a particular subclass is instantiated.Oh —
NSURLConnectiondoesn’t useinitas the designated initializer. It needs a request. More likely than not, by callinginit, you aren’t actually initializing the class and it crashes rather spectacularly as a result of undefined internal state.Use
initWithRequest:....