使用UIWebView loadRequest的General-Block 56,1024,8,244,24内存泄漏 [英] General-Block 56, 1024, 8, 244, 24 Memory Leaks using UIWebView loadRequest

查看:66
本文介绍了使用UIWebView loadRequest的General-Block 56,1024,8,244,24内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了内存泄漏,我无法通过泄漏,构建/分析或整体检查如何修复。我有一个非常强烈的概念,那是由于我的UIWebview加载javascript的loadRequest命令,但我无法弄清楚是什么问题。

I'm getting memory leaks that i can't figure out through leaks, build/analyze or overall inspection how to repair. I have a very strong notion that it's due to the loadRequest command from my UIWebview loading javascript, but I can't figure out what's wrong.

这是我的设置:

我有一个使用4个视图控制器以编程方式创建的tabbarcontroller:分别是表视图,mapview,另一个表视图和webview。

I have a tabbarcontroller that i programatically create with 4 view controllers: a table view, a mapview, another table view and a webview, respectively.


  • 第一个tableview显示静态数据。

  • mapview显示注释,点击时填充第4个选项卡的变量webview,并切换到webview以显示本地存储的三维模型html / javascript文件

  • 第二个tableview是mapview中每个注释所代表的所有相同信息的列表,仅在表格。它在填充变量方面具有相同的功能,在webview中切换和显示html / javascript文件。

  • webview显示加载的html / javascript文件,如果没有显示UIAlertView从mapview或列表中选择一个

  • the 1st tableview shows static data.
  • the mapview shows annotations that when clicked populates a variable of the 4th tab, the webview, and switches to the webview to display a locally stored html/javascript file that is a 3d model
  • the 2nd tableview is a listing of all the same information each annotation in the mapview represents, just in table form. it has the same functionality in terms of populating the variable, switching and displaying the html/javascript file in the webview
  • the webview displays the html/javascript file loaded, if not it shows a UIAlertView to select one from the mapview or the list

当我最终从webview执行loadRequest()时,最初一切正常。然而,当我开始在标签之间切换并查看不同的3D模型时(即转到地图视图,单击注释以显示模型x,在webview中观看它,然后切换到列表并单击一行以显示模型y(或x也是)并在webview中观察它加载)我开始在ipad上接收内存泄漏,而不是模拟器。这些内存泄漏几乎总是如下:General-Block 56,1024,8,244& 24并没有负责任的框架,库或堆栈跟踪跟进。

when i finally get to executing the loadRequest() from the webview, initially everything works fine. however, when i begin to switch between tabs and view different 3d models (i.e. go to the map view click an annotation to show say model x, watch it load in the webview, then switch to the listing table and click a row to show model y (or x too) and watch it load in the webview) i start receiving memory leaks on the ipad, not the simulator. these memory leaks are almost always: General-Block 56, 1024, 8, 244 & 24 and have no responsible frames, libraries or stack traces to follow up with.

在webview中如果我注释掉loadrequest行或者使用请求对象= nil执行loadrequest,我没有内存泄漏,但当我切换到使用url时指向本地文件的对象(我甚至尝试将其指向google.com,它有javascript)它会在内存泄漏中爆发。

in the webview if i comment out the loadrequest line or do a loadrequest with the request object = nil, i have no memory leaks, but when i switch to using a url object that points to the local files (i even tried pointing it to google.com, which has javascript) it erupts in memory leaks.

我试图做每个其中:


  • [self.webView loadRequest:nil];

  • [self.webView loadHTMLString :@baseURL:nil];

  • [self.webView stopLoading];

在我的webViewController的viewWillDisappear中尝试完全清理webview以便将来重用,但它似乎没有提供太多帮助。我还尝试在执行loadRequest之前执行此操作但是我得到了相同的内存泄漏。

in viewWillDisappear of my webViewController in attempt to completely clean out the webview for reuse in the future, but it doesn't seem to be doing much help. i've also attempted doing this prior to doing the loadRequest but i get the same memory leaks.


  • fyi,我正在运行最新的xcode 4.0.2和ipad有一个最新更新,4.3.2

  • 来自我评论过的上一篇文章但没有收到回复(general-block内存泄漏)我相信问题已与做事实上,当我切换视图时,webview不知道如何完全摆脱javascript

  • 我使用没有javascript的简单html文件进行了测试,并且一般块内存泄漏是不见了。但是,我得到其他cfnetwork / http消息内存泄漏,但这是一个不同的故事,而不是我目前的担忧。

  • fyi, i'm running the latest xcode 4.0.2 and the ipad has the latest update, 4.3.2
  • from a previous post i commented on and haven't heard back from (general-block memory leak) i believe the problem has to do with the fact that webview doesn't know how to fully rid itself of the javascript when i switch views
  • i did a test with a simple html file with no javascript and the general-block memory leaks are gone. however, i get other cfnetwork / http message memory leaks but that's a different story and not of my concern at the moment.

下面是单击mapView上的其中一个注释的示例代码,触发webViewController中的loadModel函数:

below is example code of when one of the annotations on the mapView is clicked which triggers the loadModel function in the webViewController:

- (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];

下面是我的webViewController.h& .m:

below is my webViewController.h & .m:

WebViewController.h:

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;

WebViewController.m:

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];
}

如果您有任何建议或更正,我将不胜感激。我有<一个星期来解决这个问题,如果你能给我任何见解,我将非常感谢你。

if you have any advice or corrections, i'd greatly appreciate it. i have < 1 week to figure this out and would highly thank you if you could give me any insight.

谢谢!

-Mike

推荐答案

迈克,我不确定你是故意还是错误地跟进?

Mike, I am not sure whether you are doing following intentionally or by mistake?

- (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?
} 

这篇关于使用UIWebView loadRequest的General-Block 56,1024,8,244,24内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆