根据仪器显示,WebView 似乎正在泄漏。通用Block-56
Instruments 报告了很多泄漏,例如:
GeneralBlock-56
GeneralBlock-8192
GeneralBlock-2048
GeneralBlock-24
GeneralBlock-32
GeneralBlock-8
GeneralBlock-16
当我打开一个仅显示 UIWebView 的类时,这一切都会发生。
以下是该类代码的核心内容:
appDelegate = (DemoSAPAppDelegate *)[[UIApplication sharedApplication] delegate];
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)];
aWebView.scalesPageToFit = YES;
[aWebView setBackgroundColor:[UIColor clearColor]];
[aWebView setOpaque:NO];
NSURL *url = [NSURL URLWithString:self.urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[aWebView loadRequest:requestObj];
[[[aWebView subviews] lastObject] setScrollEnabled:YES];
[self.view addSubview:aWebView];
[aWebView release];
我在这里做错了什么吗? WebView 在最后发布。
我需要使用像自动释放池这样的东西吗?
看到我的应用程序因此而内存溢出,我感到非常困惑。
Instruments is reporting a lot of leaks like :
GeneralBlock-56
GeneralBlock-8192
GeneralBlock-2048
GeneralBlock-24
GeneralBlock-32
GeneralBlock-8
GeneralBlock-16
This all happens when I open a class that just displays a UIWebView.
Here is the guts of the code from the class:
appDelegate = (DemoSAPAppDelegate *)[[UIApplication sharedApplication] delegate];
UIWebView *aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 480, 320)];
aWebView.scalesPageToFit = YES;
[aWebView setBackgroundColor:[UIColor clearColor]];
[aWebView setOpaque:NO];
NSURL *url = [NSURL URLWithString:self.urlString];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[aWebView loadRequest:requestObj];
[[[aWebView subviews] lastObject] setScrollEnabled:YES];
[self.view addSubview:aWebView];
[aWebView release];
Am I doing something wrong here? The WebView is released there at the end.
Do I need to use something like an autoreleasepool?
Quite confused to see my app hemorrhage memory over this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是在实际设备上吗?还是模拟器?模拟器使用的框架在很多地方都存在漏洞;它们不像设备二进制文件那样精细调整。始终在实际设备上进行测试;模拟器,终究只是模拟。
Is that on an actual device? Or the simulator? The frameworks the simulator uses leaks in many places; they are not as finely tuned as the device binaries. Always test on an actual device; the simulator, is after all, just a simulation.