MBProgressHUD中的内存泄漏

时间:2012-05-16 07:43:18

标签: iphone memory-management

在下面的代码中有大约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;
        }
    }

请帮忙。

1 个答案:

答案 0 :(得分:0)

你没有发布progressDialog或者它是ivar,然后使用property而不是ivar,并合成它,然后按照这个approch

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