Break on EXC_BAD_ACCESS in XCode?
Posted
by jasonh
on Stack Overflow
See other posts from Stack Overflow
or by jasonh
Published on 2009-10-25T21:11:49Z
Indexed on
2010/05/23
4:40 UTC
Read the original article
Hit count: 447
I'm new to iPhone development and XCode in general and have no idea how to begin troubleshooting an EXC_BAD_ACCESS
signal. How can I get XCode to break at the exact line that is causing the error?
I can't seem to get XCode to stop on the line causing the problem, but I do see the following lines in my debug console:
Sun Oct 25 15:12:14 jasonsmacbook TestProject[1289] : CGContextSetStrokeColorWithColor: invalid context
Sun Oct 25 15:12:14 jasonsmacbook TestProject[1289] : CGContextSetLineWidth: invalid context
Sun Oct 25 15:12:14 jasonsmacbook TestProject[1289] : CGContextAddPath: invalid context
Sun Oct 25 15:12:14 jasonsmacbook TestProject[1289] : CGContextDrawPath: invalid context
2009-10-25 15:12:14.680 LanderTest[1289:207] *** -[CFArray objectAtIndex:]: message sent to deallocated instance 0x3c4e610
Now, I am attempting to draw to the context I retrieve from UIGraphicsGetCurrentContext()
and pass to the object that I want to draw with.
Further trial and error debugging and I found that an NSMutableArray
I have a property for on my class was a zombie. I went into the init
function for the class and here's the code I was using:
if ((self = [super init])) {
NSMutableArray *array = [NSMutableArray array];
self.terrainBlocks = array;
[array release];
}
return self;
}
I removed the [array release]
line and it no longer gives me the EXC_BAD_ACCESS
signal, but I'm now confused about why this works. I thought that when I used the property, it automatically retained it for me, and thus I should release it from within init
so that I don't have a leak. I'm thoroughly confused about how this works and all the guides and Stackoverflow questions I've read only confuse me more about how to set properties within my init method. There seems to be no consensus as to which way is the best.
© Stack Overflow or respective owner