我目前正在iOS 5.1上构建一个使用ARC的导航控制器应用程序。我经常需要显示网页,并且已经创建了一个网页查看器,它只是一个带有一些自定义内容的UIWebView。当用户完成浏览页面后,他们点击后退按钮,这应该释放与自定义网页查看器相关联的所有内存。我的问题是,当点击后退按钮时,并不是所有内存都被释放。我已经构建了一个玩具应用程序(在github上),它只是几个按钮,每个按钮都有一个第一响应者,调用不同的页面。
@implementation ViewController
-(IBAction)googlePressed:(id)sender
{
CustomWebView *customWebView = [[CustomWebView alloc] initWithStringURL:@"http://www.google.com"];
[self.navigationController pushViewController:customWebView animated:NO];
}
-(IBAction)ksbwPressed:(id)sender
{
CustomWebView *customWebView = [[CustomWebView alloc] initWithStringURL:@"http://www.ksbw.com/news/money/Yahoo-laying-off-2-000-workers-in-latest-purge/-/1850/10207484/-/oeyufvz/-/index.html"];
[self.navigationController pushViewController:customWebView animated:NO];
}
-(IBAction)feedProxyPressed:(id)sender
{
CustomWebView *customWebView = [[CustomWebView alloc] initWithStringURL:@"http://feedproxy.google.com/~r/spaceheadlines/~3/kbL0jv9rbsg/15159-dallas-tornadoes-satellite-image.html"];
[self.navigationController pushViewController:customWebView animated:NO];
}
-(IBAction)cnnPressed:(id)sender
{
CustomWebView *customWebView = [[CustomWebView alloc] initWithStringURL:@"http://www.cnn.com/2012/04/04/us/california-shooting/index.html?eref=rss_mostpopular"];
[self.navigationController pushViewController:customWebView animated:NO];
}
CustomWebView只是在IB中链接到UIWebView属性的UIWebView。
@implementation CustomWebView
@synthesize webView, link;
- (id)initWithStringURL:(NSString *) stringURL
{
if (self = [super init]) {
link = stringURL;
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:link];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
[webView loadRequest:urlRequest];
}
- (void)viewDidUnload
{
[super viewDidUnload];
}
我的问题是,一旦所有内容加载完毕,我将堆基线设置为初始视图控制器。然后,在加载页面并返回到视图控制器后,我会检查堆,得到以下堆快照:
编辑:
上述示例项目可以在 github 上找到。