Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocos2D iPhone-对象发送自动释放的次数太多?_Iphone_Ios_Cocos2d Iphone - Fatal编程技术网

Cocos2D iPhone-对象发送自动释放的次数太多?

Cocos2D iPhone-对象发送自动释放的次数太多?,iphone,ios,cocos2d-iphone,Iphone,Ios,Cocos2d Iphone,我将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:(in

我将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];
然后,我创建了一辆汽车,例如:

+(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];
已发送对象-自动释放次数过多


我错过了什么?谢谢。

CCSprite是自动释放的,您不需要将汽车设置为自动释放。

CCSprite是自动释放的,您不需要将汽车设置为自动释放。

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

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

这是什么意思?如果我要分配,我必须自动释放。如果我从该行中删除自动释放,Xcode会抱怨那里可能存在内存泄漏。这是什么意思?如果我要分配,我必须自动释放。如果我从该行中删除自动释放,Xcode会抱怨那里可能存在内存泄漏。我觉得这段代码很好。你能把它简化成一个测试用例并放到网上吗?我觉得这段代码很好。你能把它简化成一个测试用例并放到网上吗?