Ios 内存泄漏cocos2D-SpriteWithPriteFrameName

Ios 内存泄漏cocos2D-SpriteWithPriteFrameName,ios,memory-leaks,cocos2d-iphone,Ios,Memory Leaks,Cocos2d Iphone,请帮帮我。。 我是cosos2D游戏开发新手。 在instrument中,我在SpriteWithPriteFrameName的游戏中发现了以下代码中的漏洞 tileArray=[[CCArray alloc]initWithCapacity:11]; for (int i=1; i<=10; i++) { @autoreleasepool { CCSprite *encounter; encounter = [CCSprite spriteWithSpriteFrameName:@"82

请帮帮我。。 我是cosos2D游戏开发新手。 在instrument中,我在SpriteWithPriteFrameName的游戏中发现了以下代码中的漏洞

tileArray=[[CCArray alloc]initWithCapacity:11];
for (int i=1; i<=10; i++) {
@autoreleasepool {
CCSprite *encounter;
encounter = [CCSprite spriteWithSpriteFrameName:@"82x60.png"];
[self addChild:encounter z:i tag:2600+i];
encounter.position=CGPointMake(-1000,-1000);
[tileArray addObject:encounter];
}
}
tilarray=[[CCArray alloc]initWithCapacity:11];

对于ur onExit方法中的(int i=1;i),清除精灵表,并从self中删除所有子项

-(void)onExit
 {
    [tileArray release];

    CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache];

    [cache removeSpriteFramesFromFile:@"yourSpriteSheet.plist"];

    [self removeAllChildrenWithCleanup:YES];

    [super onExit];


 }

在ur onExit方法中,清除精灵表,并从self中删除所有子项

-(void)onExit
 {
    [tileArray release];

    CCSpriteFrameCache *cache = [CCSpriteFrameCache sharedSpriteFrameCache];

    [cache removeSpriteFramesFromFile:@"yourSpriteSheet.plist"];

    [self removeAllChildrenWithCleanup:YES];

    [super onExit];


 }

您的tileray未发布,这就是为什么您会泄漏。只需将其设置在自动释放池中

tileArray=[[[CCArray alloc]initWithCapacity:11] autorelease];

您的tileray未发布,这就是为什么您会泄漏。只需将其设置在自动释放池中

tileArray=[[[CCArray alloc]initWithCapacity:11] autorelease];

你在任何地方发布你的Tilerray吗?在scene的Dealoc方法中是的,你在任何地方发布你的Tilerray吗?在sceneonExit方法的Dealoc方法中是的,如果我移除精灵帧,并再次调用recall相同的场景,那么我的应用程序就会崩溃,说它找不到那些精灵帧。即使在init方法中,我也会使用following代码CCSpriteFrameCache*frameCache=[CCSpriteFrameCache sharedSpriteFrameCache];[frameCache addSpriteFramesWithFile:@“art.plist”];CCSpriteBatchNode*art=[CCSpriteBatchNode batchNodeWithFile:@“art.png”];[self addChild:art z:0];在你的OneNet方法中添加它,并在onExit方法中删除它。不要在你的场景初始化中访问它。将你的所有代码从初始化移到OneNet。我按照你的建议将所有代码从初始化移到了OneNet方法,我的应用程序没有崩溃,但泄漏问题仍然存在。@rishabhjain86,使用CoCoCoS2D obj.C,对了,那么为什么要使用@autoreleasepool?已经有了吗我也试过了,但也不起作用。上面代码中的每个精灵都会产生432KB.onExit方法的漏洞,如果我移除精灵帧,并再次调用调用调用相同的场景,那么我的应用程序就会崩溃,说它找不到那些精灵帧。即使在init方法中,我使用了以下code CCSpriteFrameCache*frameCache=[CCSpriteFrameCache sharedSpriteFrameCache];[frameCache addSpriteFramesWithFile:@“art.plist”];CCSpriteBatchNode*art=[CCSpriteBatchNode batchNodeWithFile:@“art.png”];[self addChild:art z:0];在你的OneNet方法中添加它,并在onExit方法中删除它。不要在你的场景初始化中访问它。将你的所有代码从初始化移到OneNet。我按照你的建议将所有代码从初始化移到了OneNet方法,我的应用程序没有崩溃,但泄漏问题仍然存在。@rishabhjain86,使用CoCoCoS2D obj.C,对了,那么为什么要使用@autoreleasepool?已经有了吗在lib中使用了它。所以删除它并尝试。我也尝试了,但它也不起作用。上面代码中的每个精灵都会产生432KB的泄漏。