0

在下面的代码中有大约 3MB 的泄漏。如果我删除[self.view addSubview:progressDialog]; 它们,那么它们就没有泄漏。

    -(void)showProgressDialog:(NSString*)title setTimer:(BOOL)isTimerSet
    {
        progressDialog = [[MBProgressHUD alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; 
        [progressDialog setLabelText:title];
        progressDialog.dimBackground=YES;
        [self.view addSubview:progressDialog];//Leak is here
        [progressDialog show:YES];
    }

    -(void)hideProgressDialog
    {
        if(progressDialog !=nil)
        {
            [progressDialog hide:YES];
            [progressDialog removeFromSuperview];
            [progressDialog release];
            progressDialog = nil;
        }
    }

请帮忙。

4

1 回答 1

0

你没有释放它progressDialog或者如果它是ivar,那么使用属性而不是ivar,并合成它,然后按照这个方法

   MBProgressHUD *obj = [[MBProgressHUD alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; 
   self.progressDialog=obj;
   [obj release];

像这样

    MBProgressHUD *obj = [[MBProgressHUD alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; 
    self.progressDialog=obj;
    [obj release];        
    [self.progressDialog setLabelText:title];
    self.progressDialog.dimBackground=YES;
    [self.view addSubview:self.progressDialog];//Leak is here
    [self.progressDialog show:YES];
于 2012-05-16T07:44:23.053 回答