You can select an object in one thread and release it in another. However, depending on how you approach it, your code may do it wrong.
Turn anim into a property if possible, so you donβt have to worry about memory management that much. If you cannot, you can apply the access pattern, but you must implement it yourself.
static CCAnimation *anim=nil; +(CCAnimation*)anim { @synchronized(self) { return [[anim retain] autorelease]; } } +(void)setAnim:(CCAnimation*)animation { @synchronized(self) { if (anim != animation) { [anim release]; anim = [animation retain]; } } } -(void)loadAnimation { NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init]; [[self class] setAnim:[[[CCAnimaton alloc] init] autorelease]]; [autoreleasepool drain]; }
source share