2015-07-02 23 views
0

我遇到了UIWebview问题。当我使用URL加载数据内容时,应用程序崩溃。它发生在一个月的某个时间。我非常厌倦它,我无法重现它。它发生在客户端的设备上。请帮帮我。在ios7.1使用url加载数据内容时UIWebview中的内存泄漏(WebCore :: CachedResource :: unregisterHandle)

  1. 异常类型的应用程序运行:EXC_BAD_ACCESS(SIGSEGV)
  2. 异常亚型:KERN_INVALID_ADDRESS”
  3. 线程2名:WebThread
  4. 线程2毁损:0的WebCore 0x38322b02 的WebCore :: CachedResource :: unregisterHandle(WebCore :: CachedResourceHandleBase *) + 110 1 WebCore 0x38322a8a WebCore :: CachedResourceHandleBase ::〜CachedResourceHandleBase()+ 14 2 WebCore 0x384b77fe WebC矿石::的MemoryCache :: pruneDeadResourcesToSize(无符号整数)+ 278 3 WebCore的0x38396aee WebCore的::的MemoryCache ::剪枝()+ 94"

以下是我们的源代码。

if ([defaults boolForKey:@"cacheEnabled"]) { 
    [[NSURLCache sharedURLCache] setMemoryCapacity:[defaults integerForKey:@"cacheSize"]]; 
} else { 
    [[NSURLCache sharedURLCache] removeAllCachedResponses]; 
    [[NSURLCache sharedURLCache] setMemoryCapacity:0]; 
} 

NSURL *url = [NSURL URLWithString:[defaults objectForKey:@"connectionURL"]]; 
NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 
{ 
    if ([data length] > 0 && error == nil) [self.webView loadRequest:request]; 
    else if (error != nil) NSLog(@"Error: %@", error); 
}]; 

在dealloc方法:

[_webView setDelegate:nil]; 
[_webView stopLoading]; 

感谢先进的!

回答

0

我认为主要问题,你正在加载请求webview不在主线程。

NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 
{ 
    if ([data length] > 0 && error == nil) [self.webView loadRequest:request]; 
    else if (error != nil) NSLog(@"Error: %@", error); 
}]; 

1 /你应该PARAM队列更改为[NSOperationQueue mainQueue]

2 /其他错误(不崩溃有关):你负荷的WebView前应检查response.statuscode == 200:d