met*_*ral 5 iphone memory-leaks uiwebview mkmapview ipad
我得到了内存泄漏,我无法通过泄漏,构建/分析或整体检查如何修复.我有一个非常强大的概念,它是由于从我的UIWebView加载JavaScript的命令的loadRequest,但我无法弄清楚什么是错的.
这是我的设置:
我有一个tabbarcontroller,我编程与4-视图控制器创建:一个表格图,MapView类,另一个表视图和网页视图,分别.
当我最终从webview执行loadRequest()时,最初一切正常.然而,当我开始在标签之间切换并查看不同的3D模型时(即转到地图视图,单击注释以显示模型x,在webview中观看它,然后切换到列表并单击一行以显示模型y(或者x也是)并且在webview中观察它的负载)我开始在ipad上接收内存泄漏,而不是模拟器.这些内存泄漏几乎总是如下:通用块56,1024,8,244和24,并且没有负责任的帧,库或堆栈跟踪.
在webview中,如果我注释掉loadrequest行或者使用请求对象= nil执行loadrequest,我没有内存泄漏,但是当我切换到使用指向本地文件的url对象时(我甚至尝试将其指向Google .com,它有javascript)它在内存泄漏中爆发.
我试图做以下每一件事:
在我的webViewController的viewWillDisappear中尝试完全清理webview以便将来重用,但它似乎没有提供太多帮助.我还尝试在执行loadRequest之前执行此操作,但我得到了相同的内存泄漏.
下面是单击mapView上的其中一个注释的示例代码,它触发webViewController中的loadModel函数:
- (void) mapCallOutPressed: (UIView *) sender {
NSInteger selectedIndex = sender.tag;
MyLocation *selectedObject = [_mapView.annotations objectAtIndex:selectedIndex];
MyModel *model = selectedObject.model;
NSLog(@"Model selected from mapview = %@", model.description);
// Get reference to the webview from the tabBarController (viewController's index=3)
WebViewController *webViewController = [self.tabBarController.viewControllers objectAtIndex:3];
webViewController.model = model;
[webViewController loadModel];
// Switch tabs to the webView
self.tabBarController.selectedIndex = 3;
[self.tabBarController.selectedViewController viewDidAppear:YES];
Run Code Online (Sandbox Code Playgroud)
下面是我的webViewController.h和.m:
WebViewController.h:
WebViewController : UIViewController <UIWebViewDelegate> {
UIWebView *webView;
NSString *templateRunFilePath;
MyModel *model;
NSString *templateRunTitle;
@property (nonatomic, retain) UIWebView *webView;
@property (assign) MyModel *model;
@property (nonatomic, copy) NSString *templateRunFilePath;
@property (nonatomic, copy) NSString *templateRunTitle;
-(void) loadModel;
Run Code Online (Sandbox Code Playgroud)
WebViewController.m:
- (void) viewDidLoad {
[super viewDidLoad];
NSLog(@"in webview did load");
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
self.webView.delegate = self;
self.webView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);
self.webView.scalesPageToFit = YES;
[self.view addSubview:self.webView];
}
- (void) viewWillAppear:(BOOL)animated {
if (self.model) {
self.tabBarController.navigationItem.title = [NSString stringWithFormat: @"%@ - %@", self.tabBarController.navigationItem.title, self.model.description];
}
else {
UIAlertView *msg = [[UIAlertView alloc] initWithTitle:@"No Model Selected"
message:@"Please select a model from the map or list tab to view."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[msg show];
[msg release];
}
}
- (void) loadModel {
NSString *localURLPath = [NSString stringWithFormat:@"%@/%@/%@", self.templateRunFilePath, self.model.folderName, self.model.modelFileName];
NSURL *url = [NSURL fileURLWithPath:localURLPath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL: url];
[self.webView loadRequest:requestObj];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
}
-(void)viewWillDisappear:(BOOL)animated {
NSLog(@"webview view will disappear");
[super viewWillDisappear:animated];
//[self.webView loadRequest:nil];
//[self.webView loadHTMLString:@"" baseURL:nil];
self.webView.delegate = nil;
}
- (void)dealloc {
self.webView.delegate = nil;
[self.webView release];
[super dealloc];
}
Run Code Online (Sandbox Code Playgroud)
如果您有任何建议或更正,我将非常感激.我有<1周的时间来解决这个问题,如果你能给我任何见解,我将非常感谢你.
谢谢!
-麦克风
迈克,我不知道你是有意还是无意地关注了?
- (void) loadModel {
[self.webView loadHTMLString:@"" baseURL:nil]; // here you are loading... or you have tried with commenting it also?
NSString *localURLPath = [NSString stringWithFormat:@"%@/%@/%@", self.templateRunFilePath, self.model.folderName, self.model.modelFileName];
NSURL *url = [NSURL fileURLWithPath:localURLPath];
NSURLRequest *requestObj = [NSURLRequest requestWithURL: url];
[self.webView loadRequest:requestObj]; // again here you are also loading?
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1921 次 |
| 最近记录: |