0

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

Burjua
  • 12,506
  • 27
  • 80
  • 111

1 Answers1

1

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
  • 3,370
  • 1
  • 16
  • 22
  • yes, I think you are right, if I change to `@property (nonatomic, assign) IBOutlet UIWebView *webView;` retainCount = 1. What is the right way? – Burjua Aug 26 '10 at 13:57
  • 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 Aug 26 '10 at 14:17
  • 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 Aug 26 '10 at 15:09
  • 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 Aug 27 '10 at 13:45