I'm seeing something weird that I can't figure out. I've just done the challenge at the end of Chapter 15 in Aaron Hillegass' Cocoa Programming for Mac OS X. You're supposed to write a document-based app that will allow the user to draw ovals. Anyway, I've got it working, but I'm seeing something that I don't understand. In it the initWithFrame: method for the view implementation, really the only thing that gets done is allocation and initialization of the NSMutableArray instance variable (ovals) used to hold the NSBezierPath's for the ovals. The code below causes no problems:
However, this code crashes immediately upon launching the application. If I run it from XCode, the debugger comes up immediately. (Either I don't know how to use the debugger, or you have to be some kind computer brain to use it, because the information it gives is really rather useless to me.)
Anyway, does anyone know why using an explicit alloc then an initWithCapacity: method as opposed to the arrayWithCapacity: makes a difference? I'm still having a pretty hard time getting my head around all the reference counting, retain/release and autorelease pool stuff in Objective-C.
I've uploaded the project here in zip format if you want to download it. The code in that project right now is in "crash" state. If it matters, I'm doing all this on an Intel Mac.
(I realize that I may not have done everything else in my code the best way or the way it should be done, but right now I'm really only concerned with figuring out the problem described here.)
Code:
- (id)initWithFrame:(NSRect)frameRect
{
if ((self = [super initWithFrame:frameRect]) != nil) {
// Add initialization code here
ovals = [[NSMutableArray alloc] initWithCapacity: 1];
}
return self;
}
However, this code crashes immediately upon launching the application. If I run it from XCode, the debugger comes up immediately. (Either I don't know how to use the debugger, or you have to be some kind computer brain to use it, because the information it gives is really rather useless to me.)
Code:
- (id)initWithFrame:(NSRect)frameRect
{
if ((self = [super initWithFrame:frameRect]) != nil) {
// Add initialization code here
ovals = [NSMutableArray arrayWithCapacity: 1];
}
return self;
}
Anyway, does anyone know why using an explicit alloc then an initWithCapacity: method as opposed to the arrayWithCapacity: makes a difference? I'm still having a pretty hard time getting my head around all the reference counting, retain/release and autorelease pool stuff in Objective-C.
I've uploaded the project here in zip format if you want to download it. The code in that project right now is in "crash" state. If it matters, I'm doing all this on an Intel Mac.
(I realize that I may not have done everything else in my code the best way or the way it should be done, but right now I'm really only concerned with figuring out the problem described here.)