2009-09-09 57 views
2

我有一個包含UIWebView(OS 3.0)的UIViewController。如果我與文件數據,只要「後退按鈕」被擊中加載和視圖被駁回,我看到EXEC_BAD_ACCESS 誤差的WebCore對象釋放「SharedBuffer」當從文件加載而不是URL加載時,內存泄露UIWebView?

- (void)viewDidLoad { 
    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:fileName ofType:@"html"]; 
    NSData *fileHtmlData = [NSData dataWithContentsOfFile:htmlFile]; 
    [webView loadData:fileHtmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];  
} 

如果我改變上述通過請求加載,一切都很好。

NSURLRequest *request = [NSURLRequest requestWithURL:url]; 
[webView loadRequest:request]; 

在我的控制器的dealloc,我釋放的WebView有以下幾點:

[webView setDelegate:nil]; 
[webView release]; 

堆棧跟蹤低於:

#2 0x359d34ae in WebCore::SharedBuffer::~SharedBuffer 
#3 0x358fdab8 in WebCore::DocumentLoader::~DocumentLoader 
#4 0x332d3c00 in WebDocumentLoaderMac::~WebDocumentLoaderMac 
#5 0x358fec8c in WebCore::FrameLoader::detachFromParent 
#6 0x332d8830 in -[WebView(WebPrivate) _close] 
#7 0x332d8757 in -[WebView close] 
#8 0x332d86db in -[WebView dealloc] 
#9 0x35890719 in WebCoreObjCDeallocOnWebThreadImpl 
#10 0x358d29ce in HandleWebThreadReleaseSource 

有沒有別的東西,我需要做的,以防止泄漏/ bad_access錯誤?

+0

呃,爲什麼你在這裏說話泄漏的?我看到你所描述的是一場崩潰。內存泄漏在哪裏? (對不起,這應該是作爲評論發佈的,而不是回答。太晚了,幾秒前提交它們之後甚至不能刪除自己的帖子) – 2010-05-06 16:53:01

回答

0

原來,你需要做的在這裏列出的步驟:

https://devforums.apple.com/message/10741#10741

專門吉姆提出的建議:

- (void)webViewDidStartLoad:(UIWebView *)webView 
{ 
    [webView.delegate retain]; 

    // logic ... 
} 
- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    // logic ... 

    [webView.delegate release]; 
} 
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error 
{ 
    // error logic ... 
    [webView.delegate release]; 
} 

-(void)viewWillDisappear:(BOOL)animated 
{ 
    [super viewWillDisappear:animated]; 

    if (m_webView.loading) 
    { 
     [m_webView stopLoading]; 
    } 

    // further logic ... 
} 

- (void)dealloc { 
    m_webView.delegate = nil; 
    [m_webView release]; 
    ... 
    [super dealloc]; 
}