2012-05-16 28 views
0

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

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

请帮助。

回答

0

你是不是释放它progressDialog或者如果它是伊娃,然后使用属性,而不是伊娃和合成它,然后按照这个计算策略

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

其实泄漏发生在CGRectMake即initWithFrame:CGRectMake() –

+0

这个init方法返回一个对象,其中有一个retaincount增量存储在progressDialog中,下一次如果再次按下按钮则增加一个,而不释放它。如果你释放它。我希望它能解决 – Saad

+0

我在hideProgressDialog方法中释放它。 –