uiwebview和巨大的记忆丧失 [英] uiwebview and huge memory loss

查看:88
本文介绍了uiwebview和巨大的记忆丧失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用UIWebViews时遇到问题,我在这里看到了同样的问题,但没有帮助答案。问题在于: UIWebView内存管理。我会引用它:

I have a problem using UIWebViews, I've seen the same question here but there wasn't helpful answer. the question is here: UIWebView memory management . I will quote it:


我正在开发一个大量使用UIWebView的应用程序。这个应用程序在从我的服务器加载内容时动态生成大量的UIWebViews。其中一些UIWebView非常大,并且有很多图片。

I am developing an application that makes heavy use of UIWebView. This app generates dynamically lots of UIWebViews while loading content from my server. Some of these UIWebViews are quite large and have a lot of pictures.

如果我使用仪器检测泄漏,我没有检测到任何。然而,分配了很多对象,我怀疑这与UIWebViews有关。

If I use instruments to detect leaks, I do not detect any. However, lots of objects are allocated and I suspect that has to do with the UIWebViews.

当webviews因不再需要而发布时,似乎并非所有内存都被释放。我的意思是,在向我的服务器发出请求之后,该应用程序创建了一个UITableView和许多webview(仪器说大约8Mb)。当用户点击时,所有这些都被释放但内存使用量仅下降约2-3 Mb,使用该应用程序5-10分钟后它崩溃。

When the webviews release because no longer needed, it appears that not all memory is released. I mean, after a request to my server the app creates an UITableView and many webviews (instruments say about 8Mb). When user tap back, all of them are released but memory usage only decrements about 2-3 Mb, and after 5-10 minutes using the app it crashes.

我已经创建了简单的测试应用程序并且具有相同的结果。

I have created simple test app and have the same results.

这是一个tableView,我正在创建这样的DetailsView:

It's a tableView, I'm creating DetailsView like this:

DetailsVC *detailViewController = [[DetailsVC alloc] initWithNibName:@"DetailsVC" bundle:nil];
detailViewController.n = indexPath.row;
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];

我在IB中创建了一个webView。我加载这样的html:

in DetailsVC I have a webView created in IB. I load html like this:

    NSString *urlAddress;
if (self.n == 0)
{
    urlAddress = @"http://www.google.com";
}
else 
{
    urlAddress = @"http://www.yahoo.com";
}

NSURL *url = [NSURL URLWithString:urlAddress];

NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

[self.webView loadRequest:requestObj];

我也这样做:

- (void)viewDidUnload {
self.webView = nil;
}

就是这样,每次我在RootViewController中选择任何webView我都会失去2 -3 Mb的内存,有这个问题的解决方案吗?

That's it, every time I choose any webView in RootViewController I'm loosing 2-3 Mb of memory, Is there a solution to this problem?

谢谢。

推荐答案

只需检查以下
1.您是否将webview作为属性将其删除
2.并将以下代码放入 didFinishLaunchingWithOptions in Appdelegate

Just check the following 1. Is u make the webview as property remove it 2. And put the following code in didFinishLaunchingWithOptions in Appdelegate

    NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
    [NSURLCache setSharedURLCache:sharedCache];
    [sharedCache release];

我认为你的问题已经解决了

I think then ur problem is solved

这篇关于uiwebview和巨大的记忆丧失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆