【问题标题】:In-App browser increases memory consumption in iOS应用内浏览器会增加 iOS 中的内存消耗
【发布时间】:2014-06-17 07:03:15
【问题描述】:

在我的应用中,用户可以访问链接。我为此使用应用内浏览器。但是当用户访问该站点时,内存消耗从 25MB 增加到 50MB,并且即使用户关闭浏览器或返回上一个屏幕也不会减少。

这是我用来打开浏览器的简单代码:

    AppMainBrowserViewController *mainBrowser = [[AppMainBrowserViewController alloc] initWithNibName:@"AppMainBrowserViewController" bundle:nil];
    mainBrowser.urlString = urlString;
    [self.navigationController pushViewController:mainBrowser animated:YES];

在我的AppMainBrowserViewController

if ([InternetDetector isNetAvailable]) {

    if (self.processingIndicatorAlertView == Nil) {
        [self showIndicatorView];
    }

    //Request
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.urlString]];
    [self.mainWebView loadRequest:request];
} else {

    UIAlertView *errorAlert = [[UIAlertView alloc] initWithTitle:ALERT_TITLE_MSG message:INTERNET_NOT_FOUND_MSG delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [errorAlert show];
}

我哪里出错了?

【问题讨论】:

    标签: ios objective-c memory-management memory-leaks


    【解决方案1】:

    这很可能是由于NSURLCache 的缓存。在启动应用内浏览器之前尝试一下,它只是将缓存设置为 0:

     int cacheSizeMemory = 0; 
        int cacheSizeDisk = 0; 
        NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"];
        [NSURLCache setSharedURLCache:sharedCache];
    

    【讨论】:

    • 仍然消耗相同的内存。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-13
    • 2021-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多