So I'm trying to load a web URL (http://www.google.com) in the web view I am I had this application in which I was working, but it was boiled in an original application to remove other variables. I have at least one app setup, a view controller with the webwalk as its primary view, for the code I have
- (zero) viewDidoad {[Super Viewedload]; UIWebView * webView = (UIWebView *) self.view; NSMutableString * urlString = [[NSMutableString alloc] initWithString: @ "http://www.google.com"]; NSDRL * URL = [[NSRL Alok] InitwithString: URL String]; NSURLRequest * urlRequest = [[NSURLRequest alloc] initWithURL: url]; NSLog (sending web request to @@ @ urlString); [WebView loadRequest: urlRequest]; [UrlRequest release]; [Url delok]; [UrlString dealloc]; } And when it loads, I get an EXC_BAD_ACCESS crash inside the web thread. I am unsure if this is a problem related to the fact that I am working in a simulator, or something that I've messed with setup.
call dealloc no. Instead of calling url and urlString
The reason is that the other objects contain references to those objects, and when you dealloc < / Code> says that you are clearly destroying them, this is causing the EXC_BAD_ACCESS because when you try to access other object urls and string objects, they are already Have been destroyed. This whole issue of reference count is done with those items, so if you say:
[url release]; [UrlString release]; You are declaring this. This reduces the count of references to those objects but above, you said:
NSURL * url = [[NS URL light] initWithString: urlString]; This means url is probably a reference to that string. So when you have made it, then it will have to be maintained . So after releasing the string, it does not get lost because the url is still a reference to it when it is done with IT, it will also release it, and then (if on any object Do not claim), it will automatically be dealloc ed, because its count will be zero Always keep in mind that when you work with this type of memory management Who else will use your items? You can read more about it.
Comments
Post a Comment