質問

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