在分析我的应用程序后,我似乎在这个方法的某个地方有内存泄漏:
- (void) didEvaluateActions {
for (int x = 0; x < self.children.count; x++) {
if ([self.children[x] isKindOfClass:[BallNode class]]) {
BallNode * ball = (BallNode *) self.children[x];
if (abs(ball.physicsBody.velocity.dx) < BALL_MIN_VEL_X) {
ball.physicsBody.velocity = CGVectorMake((ball.physicsBody.velocity.dx < 0 ? -1 : 1) * BALL_MIN_VEL_X, ball.physicsBody.velocity.dy);
}
if (abs(ball.physicsBody.velocity.dx) > BALL_MAX_VEL_X) {
ball.physicsBody.velocity = CGVectorMake((ball.physicsBody.velocity.dx < 0 ? -1 : 1) * BALL_MAX_VEL_X, ball.physicsBody.velocity.dy);
}
if (abs(ball.physicsBody.velocity.dy) < BALL_MIN_VEL_Y) {
ball.physicsBody.velocity = CGVectorMake(ball.physicsBody.velocity.dx, (ball.physicsBody.velocity.dy < 0 ? -1 : 1) * BALL_MIN_VEL_Y);
}
if (abs(ball.physicsBody.velocity.dy) > BALL_MAX_VEL_Y) {
ball.physicsBody.velocity = CGVectorMake(ball.physicsBody.velocity.dx, (ball.physicsBody.velocity.dy < 0 ? -1 : 1) * BALL_MAX_VEL_Y);
}
}
}
}
我没有看到这种方法可能导致内存泄漏的地方。BallNode 不是在这里创建的,那么为什么仪器会指向这个位置呢?这种方法如何导致泄漏?
-预先感谢