Cocos2d iphone 为什么我的电脑内存在泄漏?
我有以下代码:Cocos2d iphone 为什么我的电脑内存在泄漏?,cocos2d-iphone,Cocos2d Iphone,我有以下代码: CCParticleExplosion *explosion = [[CCParticleExplosion alloc] init]; explosion.texture = [[CCTextureCache sharedTextureCache] addImage:@"chick.png"]; explosion.position = egg.position; [explosion setAutoRemoveOnFinish:YES]; [e
CCParticleExplosion *explosion = [[CCParticleExplosion alloc] init];
explosion.texture = [[CCTextureCache sharedTextureCache] addImage:@"chick.png"];
explosion.position = egg.position;
[explosion setAutoRemoveOnFinish:YES];
[explosion setTotalParticles:10];
[self.layer addChild:explosion];
我认为setAutoRemoveonfish会自动从层中删除爆炸节点并释放它。但是xCode仪器说是内存泄漏
更新1:
使用CCParticleExplosion节点代替alloc解决了此问题 如果将某些内容分配到内存中,则必须取消分配 节点是一种创建方法,它通过自动释放池处理内存分配
[ explosion autorelease];
将上面的行添加到代码中
CCParticleExplosion *explosion = [[CCParticleExplosion alloc] init];
explosion.texture = [[CCTextureCache sharedTextureCache] addImage:@"chick.png"];
explosion.position = egg.position;
[explosion setAutoRemoveOnFinish:YES];
[explosion setTotalParticles:10];
[self.layer addChild:explosion];
[ explosion autorelease];
只需使用
[爆炸释放]代码>使用完毕后