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