1
我已经编写了管理我的应用程序的所有网络调用的网络类。有两种方法showLoadingAnimationView
和hideLoadingAnimationView
,它们将在视图上显示UIActivityIndicatorView,并显示具有淡入淡出背景的当前视图控制器。我在这两种方法的某处发生内存泄漏。下面是代码加载动画内存泄露
-(void)showLoadingAnimationView
{
textmeAppDelegate *textme = (textmeAppDelegate *)[[UIApplication sharedApplication] delegate];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
if(wrapperLoading != nil)
{
[wrapperLoading release];
}
wrapperLoading = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
wrapperLoading.backgroundColor = [UIColor clearColor];
wrapperLoading.alpha = 0.8;
UIView *_loadingBG = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 480.0)];
_loadingBG.backgroundColor = [UIColor blackColor];
_loadingBG.alpha = 0.4;
circlingWheel = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
CGRect wheelFrame = circlingWheel.frame;
circlingWheel.frame = CGRectMake(((320.0 - wheelFrame.size.width)/2.0), ((480.0 - wheelFrame.size.height)/2.0), wheelFrame.size.width, wheelFrame.size.height);
[wrapperLoading addSubview:_loadingBG];
[wrapperLoading addSubview:circlingWheel];
[circlingWheel startAnimating];
[textme.window addSubview:wrapperLoading];
[_loadingBG release];
[circlingWheel release];
}
-(void)hideLoadingAnimationView
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
wrapperLoading.alpha = 0.0;
[self.wrapperLoading removeFromSuperview];
//[NSTimer scheduledTimerWithTimeInterval:0.8 target:wrapperLoading selector:@selector(removeFromSuperview) userInfo:nil repeats:NO];
}
这里是我如何调用这两个方法
[NSThread detachNewThreadSelector:@selector(showLoadingAnimationView) toTarget:self withObject:nil];
,然后在某个地方的代码后,我使用下面的函数调用来隐藏动画。
[self hideLoadingAnimationView];
我在调用showLoadingAnimationView函数时出现内存泄漏。代码中是否有任何错误,或者在我们进行网络调用时是否有更好的技术来显示加载动画?
您确定这是唯一的问题,因为即使在hideLoadingAnimationView中释放对象也没有解决问题。 – 2010-06-18 14:33:30