gpt4 book ai didi

iphone - UIWebView 的内存问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:50:41 26 4
gpt4 key购买 nike

我有一个 webviewcontroller,我为其创建了一个实例,然后更改请求,并根据在 tableview 中选择的行显示 webview。

// Replace tableView:didSelectRowAtIndexPath with the following
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{

CGRect rect = self.view.frame;
CGFloat width = [UIScreen mainScreen].bounds.size.width;
CGFloat height = [UIScreen mainScreen].bounds.size.height;
rect.size.width = width; //self.view.frame.size.width;
rect.size.height = height; //self.view.frame.size.height;
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];

page = [[WebViewController alloc] initWithUrl:entry.articleUrl];
page.view.frame = rect;
[self.view addSubview:page.view];

}

我的问题是,加载其中一些后,我收到内存警告并崩溃。

在另一个标签中,我还有一个 webview,它在标签加载时加载谷歌地图。这几乎在加载应用程序后立即使应用程序崩溃。

因为我只为每一个创建了一个实例,所以我不明白为什么会出现这个问题。之前每次都是新建一个webviewcontroller,然后release,还是一样的问题。

这是加载谷歌地图的代码:

@interface MapViewController : UIViewController {
IBOutlet UIWebView *mapPage;
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
url_string = @"http://maps.google.fr/maps/ms?msa=0&msid=213119412551786463007.0004b3fb7f4c123377402&z=12";
url = [NSURL URLWithString:url_string];
request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url_string]];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
mapPage.scalesPageToFit = YES;
mapPage.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
[mapPage loadRequest:request];
[super viewDidLoad];
}

UIWebView 是在界面生成器中创建的。

它会在 map 加载完成后立即耗尽内存并崩溃,或者在您尝试与 map 进行交互时立即崩溃。它似乎与上面的问题完全相同,但是这次没有选项卡,或者没有更改 UIWebView 使用的请求。

最佳答案

每次当您在 UITableView 中选择行时,您都会创建一个新的 WebViewController 对象并将其 View (出于某种原因?)添加到当前 Controller 的 View 中。我不确定您是否至少从 superview 中删除了该 View (您还必须释放 WebViewController)。当然,它会占用越来越多的内存。

创建一个完整的 UIViewController 并将其用作 subview 的原因是什么?为什么你不使用 UINavigationController?

关于iphone - UIWebView 的内存问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9290021/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com