I am new to iPhone programming. I have created a Window based application. Following is my code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILabel *myLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(50, 200, 200, 80)];
myLabel1.text = @"Prasad";
NSLog(@"myLabel retain Count: %d\n", [myLabel1 retainCount]);
[myLabel1 release];
NSLog(@"myLabel retain Count: %d\n", [myLabel1 retainCount]);
[window makeKeyAndVisible];
return YES;
}
Q1. When I release mylabel1, NSLog statement following the release statement still prints retainCount as 1 whereas ideally it should print 0. Also the application is running absolutely fine.
Now consider the following code: (which is similar to above code except for adding one NSLog statement: NSLog(@"Bingoooooooo Memeory Released"); )
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILabel *myLabel1 = [[UILabel alloc] initWithFrame:CGRectMake(50, 200, 200, 80)];
myLabel1.text = @"Prasad";
NSLog(@"myLabel retain Count: %d\n", [myLabel1 retainCount]);
[myLabel1 release];
NSLog(@"Bingoooooooo Memeory Released");
NSLog(@"myLabel retain Count: %d\n", [myLabel1 retainCount]);
[window makeKeyAndVisible];
return YES;
}
Now my query is,
1. When I run the above code the application gets crashed after printing NSLog(@"Bingoooooooo Memeory Released"); Why is the application getting crashed just by adding the NSLog(@"Bingoooooooo Memeory Released") statement whereas in the First Code the application is not getting crashed.