In my .h file create 3 objects like below
IBOutlet UIScrollView *scrollView;
IBOutlet UITextView *txtMessage;
IBOutlet UIWebView *webView;
In xib make Connection for all 3 objects
hierarchy in xib like
**View
---UIScrollView
---UITextView
---UIWebView**
then I am printing retainCount in dealloc method
NSLog(@"scrollView retainCount:%d",[scrollView retainCount]);
[scrollView release];scrollView=nil;
NSLog(@"txtMessage retainCount:%d",[txtMessage retainCount]);
[txtMessage release];txtMessage=nil;
NSLog(@"webView retainCount:%d",[webView retainCount]);
[webView release];webView=nil;
on console i am getting like below
scrollView retainCount:3
txtMessage retainCount:2
webView retainCount:2
I want to know why its happens like this ,and one more thing how can release this objects in dealloc method…
The answer is: you don’t release them. You didn’t alloc] init] then, they’re not your responsibility memory-wise.
The only case where they’re somehow your responsibility, is when you retain them using a @property (retain) for the IBOutlets. In that case, you’ll release them in [dealloc]
Answering to your comment in another answer about instruments and releasing the outlets that the xib creates: if you release them, then the view will be unload sometime and the responsible for releasing the elements in the .xib (which it wasn’t you) will release them again, and it will crash 😉 The reason why you go back to another view and the memory doesn’t decrease is because when a view disappears, it’s not unloaded, that only happens when either the view controller is deallocated, or when the application gets a memory warning.