我将CCSprite子类化,而我的名为Cars的类的初始化如下:

+(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太多次了?????????

我想念什么?谢谢。

最佳答案

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

关于iphone - Cocos2D iPhone-对象发送自动释放次数过多?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9602081/

10-12 13:10