Duck
Duck

Reputation: 36003

Cocos2D iPhone - Object sent autorelease too many times?

I have subclassed CCSprite and my class, named Cars, inits like this:

+(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;
}

then I create a car using, for example, something like this:

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

It appears perfect, but if I analyze the code with Xcode, it points to this line

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

saying object sent -autorelease too many times ?????????

what am I missing? Thanks.

Upvotes: 1

Views: 230

Answers (2)

BJ Homer
BJ Homer

Reputation: 49034

The code that you've shown appears correct. Either this isn't the actual code, or there's some other relevant context not shown here. The code in your question is all correct.

Upvotes: 1

Trausti Thor
Trausti Thor

Reputation: 3774

CCSprite is an autoreleased, you don't need to set your car to autorelease.

Upvotes: 0

Related Questions