2012-03-07 64 views
1

我已经子类CCSprite和我的课,名为汽车,inits这样的:Cocos2D iPhone - 对象发送过多次autorelease?

+(Cars *) carWithNumber:(int)number COLOR:(int)color SHAPE:(int)shape { 
    return [[[Cars alloc] initWithNumber:number COLOR:color SHAPE:shape] autorelease]; 
} 

-(id) initWithNumber:(int)number COLOR:(int)color SHAPE:(int)shape { 

    self = [self init]; 

    if (self) { 
     self.texture = [self createTextureWithNumber:number COLOR:color SHAPE:shape]; 
    } 

    return self; 
} 

然后我创建了一个汽车使用,例如,像这样:

Cars *oneCar = [Cars carWithNumber:2 COLOR:3 SHAPE:5]; 
[self addChild:oneCar]; 

看起来完美,但如果我分析和Xcode的代码,它指向该行

return [[[Cars alloc] initWithNumber:number COLOR:color SHAPE:shape] autorelease]; 

对象发送-autorelease过很多次 ?????????

我错过了什么?谢谢。

+1

该代码对我来说看起来很好。你能把它减少到一个测试用例并把它放到网上吗? – Jim 2012-03-07 14:29:59

回答

0

CCSprite是一个autoreleased,你不需要设置你的车autorelease。

+0

你是什么意思?如果我正在分配,我必须autorelease。如果我从该行删除autorelease,则Xcode会抱怨可能存在内存泄漏。 – SpaceDog 2012-03-07 13:49:06

1

您显示的代码显示正确。要么这不是实际的代码,要么这里没有显示其他相关的上下文。你问题中的代码都是正确的。