简体   繁体   English

应用内浏览器增加了iOS中的内存消耗

[英]In-App browser increases memory consumption in iOS

In my app, user can visit link. 在我的应用中,用户可以访问链接。 I use in-app browser for that. 我为此使用应用内浏览器。 But when user visits the site, memory consumption is increased from 25MB to 50MB and does not decrease even user closes the browser or come back to previous screen. 但是,当用户访问该站点时,内存消耗从25MB增加到50MB,并且即使用户关闭浏览器或返回到先前的屏幕也不会减少。

Here is the simple code I am using to open browser: 这是我用来打开浏览器的简单代码:

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

In my AppMainBrowserViewController : 在我的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];
}

Where I am going wrong? 我要去哪里错了?

Most probably this is due to the cache of NSURLCache . 这很可能是由于NSURLCache的缓存。 Try that before launching the in-app browser it just set the cache to 0: 尝试在启动应用内浏览器之前将缓存设置为0:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM