子视图未关闭导致内存泄漏Phonegap

时间:2013-07-25 15:24:58

标签: memory-leaks cordova childviewcontroller

我遇到无法在调用此自定义刷新时关闭CDVViewController的问题,它在后台保持加载并加载一个新的导致内存泄漏/高内存使用。我试图使用release和removeFromSuperview for webView,subview,CDVViewController,ChildViewController,但它们都不起作用。我正在通过Storyboard运行一个Tab Bar Controller,(我必须将CDVViewController作为子视图调用的另一个原因)当我通过safari使用web检查器时,我可以看到在该选项卡上构建的页面,以及当我在另一个选项卡上刷新时(不使用CDVViewController / phonegap)它工作正常。非常感谢任何帮助。

所以这是我的.h

#import <UIKit/UIKit.h>
#import <ifaddrs.h>
#import <arpa/inet.h>
#import <Cordova/CDVViewController.h>


@interface ThirdViewController : CDVViewController <UIWebViewDelegate>
{
  IBOutlet CDVViewController *webView;
  IBOutlet UIActivityIndicatorView *activityind;
}
- (IBAction)Refresh:(id)sender;


@end

我的.m

@interface ThirdViewController ()
@end
@implementation ThirdViewController


- (void)viewDidLoad
{
  webView = [CDVViewController new];
  webView.startPage = @"MYWEBSITE";   
    [self addChildViewController:webView];
    [self.webView addSubview:webView.view];

    webView.view.frame = CGRectMake(0, 0, 0, 0);
    [activityind startAnimating];
    [self.webView addSubview: activityind];
    [self CustomActivity];
}


-(void) CustomActivity
{
    if ([webView.reference isEqualToString:@"TRUE"]){   //webView.reference is something I added into phonegap CDVViewController so that I am able to see when it is being loaded/used to load the custom activity/activity ind to work.
       [activityind removeFromSuperview];
    }else{
       [NSTimer scheduledTimerWithTimeInterval:.5 target:self selector:@selector(CustomActivity) userInfo:nil repeats:NO];
    }
}

- (IBAction)Refresh:(id)sender {

    webView = [CDVViewController new];              
    webView.startPage = @"MYWEBSITE"; 

    [self addChildViewController:webView];
    [self.webView addSubview:webView.view];


    webView.view.frame = CGRectMake (0,0,self.view.frame.size.width,(self.view.frame.size.height -44));
    [activityind startAnimating];
    [self.webView addSubview: activityind];
    [self CustomActivity];
}

- (void)webViewDidStartLoad:(UIWebView *)webView {}
- (void)webViewDidFinishLoad:(UIWebView *)subview {}
- (void)loading {}
- (void)didReceiveMemoryWarning{[super didReceiveMemoryWarning];}

@end

1 个答案:

答案 0 :(得分:0)

找到解决方案,我必须实现[webView.webView reload];

- (IBAction)Refresh:(id)sender {

[webView.webView reload];

}