简体   繁体   中英

Examine cocos2d's nodes tree

I am already finishing my game and I am trying to fix some memory issues.

My game has 36 levels and I noticed that when I run it in an iPod, after 20-25 levels my app crashes. I start getting memory warnings and it always crashes when transitioning between scenes.

I have already used instruments to fix every memory leak but this is still happening. My guess is that cocos is still holding references to old objects.

I would like to find a way to look through the cocos' nodes hierarchy in certain points of my game to make sure everything is ok.

Any idea of how to do that?

I have modified CCTextureCache to log which textures are retained and which others are released, at critical steps in my games, where i force a 'removedUnusedTextures', notably on scene transitions. Whatever you see there should give a hint of where to look in your app. Also, i tend to tag everything with a unique tag, and remember the tags in every class that adds stuff to a CCNode. In the wash (cleanup), i rundown the array of tags, and force remove them.

I ended up doing this:

I added some logic in the CCDirector to "draw" the hierarchy:

-(void) printChildren:(CCNode *)node andLevel:(NSInteger)level {

    NSString *tabs = @"";
    for (int i=0; i <level; i++) {
        tabs = [NSString stringWithFormat:@"%@  ", tabs];
    }

    NSLog(@"%@NODE %@. Children count: %d", tabs, node, node.children.count);
    if ( node.children.count == 0 ) {
        return;
    } else {
        for (CCNode *child in node.children) {
            [self printChildren:child andLevel:level+1];
        }
    }
}

-(void) nodeHierarchy
{

    NSLog(@"Printing nodeHierarchy! with an stack of %d scenes", [scenesStack_ count]);
    for (CCScene *scene in scenesStack_) {
        NSLog(@"Scene in stack: %@", [scene class]);
        [self printChildren:scene andLevel:0];
    }
}

I call nodeHierarchy in the replaceScene method.

It would be great to have a more visual tool, but this worked for me.

您无法迁移到具有ARC的SDK 5.0的任何原因。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM