iphone app memory build up

妖精的绣舞 提交于 2019-12-11 19:48:56

问题


Trying to diagnose why my game is building up memory, causing it to eventually slow down to the point of unresponsiveness. Based on previously asked questions, i think i might know what's causing it, not sure though, so i will just post what i think it might be.

[self performSelector:@selector(createObstacle0) withObject:nil afterDelay:1.0];
[self performSelector:@selector(score0) withObject:nil afterDelay:1];

....

-(void)createObstacle0 {
int yMin = (CGRectGetMidY(self.frame)+190);
int yMax = (CGRectGetMidY(self.frame)+270);
CGPoint startPoint = CGPointMake(-20, yMin + arc4random_uniform(yMax - yMin));
SKSpriteNode *obstacle = [SKSpriteNode spriteNodeWithImageNamed:@"obstacle"];
obstacle.position = CGPointMake(startPoint.x, startPoint.y);
obstacle.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:21.5];
obstacle.physicsBody.categoryBitMask = enemyCategory;
obstacle.physicsBody.contactTestBitMask = playerCategory;
obstacle.physicsBody.dynamic = NO;
obstacle.name = @"obstacle0";
[self addChild:obstacle];
[obstacle runAction:[SKAction moveTo:CGPointMake(340, startPoint.y) duration:minTime + arc4random_uniform(maxTime - minTime)]];
float randomNum = arc4random_uniform(3.0) + 0.1;
[self performSelector:@selector(createObstacle0) withObject:nil afterDelay:randomNum];
}

-(void)score0 {

[self enumerateChildNodesWithName:@"obstacle0" usingBlock:^(SKNode *node, BOOL *stop) {
    if (node.position.x > 330) {
        score++;
        scorelabel.text = [NSString stringWithFormat:@"%lu",(unsigned long)score];
        [node removeFromParent];
    }

}];
[self performSelector:@selector(score0) withObject:nil afterDelay:.1];
}

I read here that perferomSelector can cause some memory problems. For me, after playing my game just once, i can sit at the main menu and both cpu and memory will just continue to rise. No idea what's going on and appreciate all help. Is the code i have here to blame?

来源:https://stackoverflow.com/questions/23209740/iphone-app-memory-build-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!