Iphone 加载动画内存泄漏
我已经编写了网络类来管理我的应用程序的所有网络调用。有两种方法Iphone 加载动画内存泄漏,iphone,objective-c,memory-leaks,performance,Iphone,Objective C,Memory Leaks,Performance,我已经编写了网络类来管理我的应用程序的所有网络调用。有两种方法showLoadingAnimationView和HideloadingOrganizationView,它们将在带有淡入淡出背景的当前viewcontroller上的视图中显示UIActivityIndicatorView。我在这两种方法的某个地方发现内存泄漏。这是密码 -(void)showLoadingAnimationView { textmeAppDelegate *textme = (textmeAppDeleg
showLoadingAnimationView
和HideloadingOrganizationView
,它们将在带有淡入淡出背景的当前viewcontroller上的视图中显示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函数时出现内存泄漏。代码中有任何错误,或者在我们进行网络调用时有没有更好的技术来显示加载动画?该方法
showLoadingAnimationView
返回一个非自动发布的视图(retainCount->1),您稍后(我假设)会将其添加到另一个视图(retainCount->2)
在
hideloadinganizationview
中,仅从其超级视图中删除视图(重新计数->1)。此方法中缺少版本
。这意味着您不应该在showLoadingAnimationView
中调用release
,您确定这是唯一的问题,因为即使在HideloadingOrganizationView中释放对象也不能解决问题。