In my cocos2d game I have a global CCLabelTTF inside one of my classes. In the init I check if another int value is positive or negative. Inside the if case where I check, I init the CCLabelTTF. When I init it, it has a pending autorelease, I have read that it is autoreleased at the end of the game loop. Is this true or is it possible for it to be autoreleased some other time, like once I go out of the scope of the if statement?

有帮助吗?

解决方案

Autoreleased objects are added to an instance of an autorelease pool (NSAutoreleasePool), which is drained at some point, usually at the end of the current runloop (if not manually).

So the end of a scope, method, if statement, etc, won't drain the pool. Your object will receive a release message only when the pool is drained, so it will still be valid for some time after your method has returned.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top