我的主要代码中有这一行:
[self performSelectorInBackground:@selector(animateMe) withObject:nil];
这是animateMe
- (void) animateMe {
[UIView animateWithDuration:1.0
animations:^{
[myView setAlpha:0.0f];
}];
}
这些是我在终端上看到的消息
*** __NSAutoreleaseNoPool(): Object 0x1af740 of class myClass autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1af740 of class myClass autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1af740 of class myClass autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x193190 of class CABasicAnimation autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1b8230 of class NSConcreteValue autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1af740 of class myClass autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1c0ee0 of class CABasicAnimation autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1b4260 of class NSCFNumber autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1aeb30 of class __NSCFDictionary autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1debd0 of class myClass autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1debd0 of class myClass autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1debd0 of class myClass autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1dad90 of class CABasicAnimation autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x16db40 of class NSConcreteValue autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1debd0 of class myClass autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1aafc0 of class CABasicAnimation autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1dfc10 of class NSCFNumber autoreleased with no pool in place - just leaking
*** __NSAutoreleaseNoPool(): Object 0x1d1470 of class __NSCFDictionary autoreleased with no pool in place - just leaking
我该如何解决?
感谢。
答案 0 :(得分:14)
- (void) animateMe {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
[UIView animateWithDuration:1.0
animations:^{
[myView setAlpha:0.0f];
}];
[pool drain];
}
答案 1 :(得分:6)
它告诉你到底出了什么问题 - 当选择器执行时你没有自动释放池。你需要添加:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
一开始,并且:
[pool drain];
在方法结束时。
答案 2 :(得分:1)
它可以帮助某人
@autoreleasepool {
//enter code here
}
答案 3 :(得分:0)
animateMe
正在新线程中执行,因为它是从performSelectorInBackground
调用的。每当你产生一个线程时,该线程应该创建并耗尽它自己的自动释放池。
来自Apple documentation: “......如果你分离一个线程,你需要创建自己的自动释放池块。”