I use this code.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
view = [[UIView alloc] init];
[_window addSubview:view];
[view release];
NSLog(@"count - %d", [view retainCount]);
[self.window makeKeyAndVisible];
return YES;
}
- (IBAction)click{
NSLog(@"count - %d", [view retainCount]);
}
When i click to uibutton – my view retain count = 2.
Why is this happening?
Please do not count on retainCount. Fire up Instruments and see if there is a leak. Apple discourages the use of retainCount for debugging purposes:
Have a look at the NSObjectProtocol and the retainCount documentation. Read the Memory Management Programming Guide for a deeper understanding of retain counts.