I got an EXC_BAD_ACCESS
in main()
, here is my code:
int main(int argc, char *argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"TestBedAppDelegate");
[pool release];
return retVal;
}
@interface TestBedAppDelegate : NSObject <UIApplicationDelegate>
@end
@implementation TestBedAppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:[[TestBedViewController alloc] init]];
[window addSubview:nav.view];
[window makeKeyAndVisible];
}
@end
- (void) action: (id) sender
{
[self highRetainCount];
}
@implementation TestBedViewController
- (void) highRetainCount
{
UIView *view = [[[UIView alloc] init] autorelease];
printf("Count: %d\n", [view retainCount]);
NSArray *array1 = [NSArray arrayWithObject:view];
printf("Count: %d\n", [view retainCount]);
[array1 autorelease]; // If comment this line, everything will be OK
}
@end
The program stopped at main()
:
int retVal = UIApplicationMain(argc, argv, nil, @"TestBedAppDelegate");
As the comment says, after commenting out [array1 autorelease];
, everything was OK.
So here is my question:
EXC_BAD_ACCESS
often indicates using an object already released. Clearly there's something to do with[array1 autorelease];
, but I can't understand their relationship.Why stopped at this position --
main()
-- instead of somewhere else?
Newbie question :)