views:

98

answers:

1

Hi guys, I have a View Controller in which I have UIwebView created in IB.

IBOutlet UIWebView *webView;

@property (nonatomic, retain) IBOutlet UIWebView *webView;

@synthesize webView;

this webView has retainCount = 2 in viewDidLoad. Why?

Thanks

+1  A: 

My guess would be that's because it's retained by your class in the webView property and it's retained by its superview inside the subviews array.

filipe
yes, I think you are right, if I change to `@property (nonatomic, assign) IBOutlet UIWebView *webView;` retainCount = 1. What is the right way?
Burjua
you can use retain, that way you make sure that your webView won't be dealloc'ed if, for example, you decide to remove it from it's superview for any reason. Just remember to release it in the appropriate place (probably in 'viewDidUnload', where you can just do 'self.webView = nil' and the setter will release it for you).
filipe
Sorry, I didn't quite get it, so I should use retain and set self.webView to nil in viewDidUnload right, Actually I have the same problem as described here: http://stackoverflow.com/questions/2950907/uiwebview-memory-management , And can't find solution to it
Burjua
Yes, you can have the webView property retain the web view, and setting that property to nil will release it (remember to use `self.webView = nil` and not just `webView = nil`). Are you sure that the view controller and the view controller's view that contains the web view are being properly released?
filipe