In a class interface I define some ivar
@property (strong,nonatomic) id < Protocol > initEst; // Initial estimate
This compiles without a problem but when I run the program it crashes with EXC_BAD_ACCESS and [Object .cxx_destruct] indicated by the debugger as the reason.
What is going on?
I have tested this some more and there seems to be three conditions for this particular quirk to show up.
In my particular case the ivar's
Protocolwas also the same as that of the containing class. This seems to be an additional requirement for this problem to surface (refering here to my earlier answer that did not mention this).So to elaborate on my earlier answer. If
initXXXis an ivaridtypeProtocolthat is the same as the containing classthen the Objective-C + ARC compiler will happily compile the code but be unable to execute it.
Here is a sample of the code I used to test
Something like this will cause problems simply because the name starts with init. Change the name and all problems disappear.
For reference, the runtime error this generates is
This snippet is pretty abstract but this may bite you in places where you need to specify some initial condition and where it is natural to name some ivar
initXxxbut beware, if you use Objective-C you do not have that luxury nor will the compiler warn you that it is wrong.The original error seemed memory allocation related and caused me to suspect the way I used the autoreleasepool but now I am fairly convinced this has nothing to do with the issue.