Another puzzler. I have an NSArray (iTours) containing 3 Objects and a retain count of 1.
This Array is released in the object dealloc method as follows:
- (void)dealloc {
NSLog(@"retain count für iTouren: %d", [iTours retainCount]);
[iTours release]; // triggers EXC_BAD_ACCESS
[super dealloc];
}
The console window shows the following message (no further details):
Program received signal:
“EXC_BAD_ACCESS”.
any clues what’s going on? What did I miss?
Most likely, you are over-releasing
iTourenand, thus, that call toreleaseis causing the crash. That is,iTourenis already deallocated by the time you release the containing array and when that containing array sendsreleaseto the already deallocatediTourenyour app crashes.(Of course,
iToursmight be the object that is already deallocated. In any case, it is an over-release problem.)Turn on zombie detection and see if that barfs up the specific problem.
Note that the
number returned by
retainCountis useless. Absolute retain counts are an implementation detail and will often be a specific value that seems like nonsense.
In this case, the final
releaseof an object does not decrement the retain count. Why? Because that’d be a wasted cycle when the object is about to be deallocated anyway. It would be impossible forretainCountto return 0 because, by definition, an object with a retain count of 0 has already been deallocated and, thus, is no longer a viable message receiver anyway.