gpt4 book ai didi

ios - XCode 4.6显示了方法+(void)beginAnimations:(NSString *)animationID context:(void *)context的内存泄漏警告。

转载 作者:行者123 更新时间:2023-12-01 16:52:04 25 4
gpt4 key购买 nike

这个问题Iphone - how to pass a parameter to animationDidStop?在上下文中提出了整个问题。根据最佳答案,我在我的animationDidStopSelector中释放了上下文。但是,由于我更新了Xcode,因此收到此警告

 - (void) helloThere: (int) myValue {

// I am trying to pass myValue to animationDidStop
[UIView beginAnimations:nil context:[[NSNumber alloc] initWithFloat:self.view.frame.origin.x]]; //Warning raised on this line
[UIView setAnimationDuration:1.0];
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
[UIView setAnimationDelegate:self];

// do stuff
[UIView commitAnimations];
}

- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

CGFloat usesThisValue = [(NSNumber *) context floatValue];
[(NSNumber *) context release];
}

日志中的警告内容为:
warning: Potential leak of an object       [UIView beginAnimations:nil context:[[NSNumber alloc] initWithFloat:self.view.frame.origin.x]]; //Warning raised on this line
1 warning generated.

有解决方案吗?如果没有,我如何为我的项目关闭此警告?

最佳答案

问题是您在此调用内分配了一个NSNumber。该号码没有被释放。尝试更改此:

[UIView beginAnimations:nil context:[[NSNumber alloc] initWithFloat:self.view.frame.origin.x]];

编辑
Here is a link to a post about handling the (void *)context

因此,您需要某种方式来保留对NSNumber的引用,以便以后可以对其进行清理。
self.contextNumber = [[NSNumber alloc] initWithFloat:self.view.frame.origin.x];
[UIView beginAnimations:nil context:self.contextNumber];

并在你的dealloc中清理它

关于ios - XCode 4.6显示了方法+(void)beginAnimations:(NSString *)animationID context:(void *)context的内存泄漏警告。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14848532/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com