J'ai un jeu de Sprite Kit que j'ai créé dans Xcode 5 et quand je le profile pour des fuites en utilisant des Instruments, je vois qu'il y a effectivement quelques fuites:
Le problème est que je ne peux pas dire d'où provient cette application, car la colonne «Cadre responsable» ne me désigne nulle part dans mon application.
Comment procéder pour déboguer / suivre les origines de ce problème?
Mise à jour # 1
Il y a un seul file dans lequel j'interagis avec CGPath mais j'appelle CGPathRelease
... CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddLineToPoint(path, NULL, size.width, 0); CGPathAddLineToPoint(path, NULL, size.width, (upperCount * size.width)); CGPathAddLineToPoint(path, NULL, 0, (upperCount * size.width)); CGPathCloseSubpath(path); upper.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path]; CGPathRelease(path); ...
Mise à jour # 2
Après avoir ouvert le panneau de droite dans Instruments, j'ai pu voir les lignes incriminées (même si je ne suis pas sûr que ce soit faux):
Le premier set de fuites …
Le deuxième set de fuites …
Avez-vous vu cette? SKPhysicsBody bodyWithPolygonFromPath memory leaks
On dirait que c'est un bug de spritekit dans SKPhysicsBody (je suppose qu'il est conservé dans bodyWithPolygonFromPath mais pas publié).
Hmm … Je ne suis pas vraiment sûr de ce qui se passe ici. Cependant, serait-il possible de l'essayer en utilisant UIBezierPath
pour créer le path à la place.
Juste pour le tester …
CGMutablePathRef path = CGPathCreateMutable(); CGPathMoveToPoint(path, NULL, 0, 0); CGPathAddLineToPoint(path, NULL, size.width, 0); CGPathAddLineToPoint(path, NULL, size.width, (upperCount * size.width)); CGPathAddLineToPoint(path, NULL, 0, (upperCount * size.width)); CGPathCloseSubpath(path); upper.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path]; CGPathRelease(path);
Deviendrait…
UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(0, 0)]; [path addLineToPoint:CGPointMake(size.width, 0)]; [path addLineToPoint:CGPointMake(size.width, (upperCount * size.width))]; [path addLineToPoint:CGPointMake(0, (upperCount * size.width))]; [path closePath]; upper.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path.CGPath];
Juste pour voir si ça arrête les fuites. Si oui … gardez le: D
Si vous devez utiliser le path plusieurs fois, vous pouvez garder une reference afin de pouvoir le charger paresseusement et ensuite le charger une seule fois.