Memory Leak in Sprite Kit Application

给你一囗甜甜゛ 提交于 2019-12-05 18:34:38
Edwin Iskandar

Have you seen this? SKPhysicsBody bodyWithPolygonFromPath memory leaks

Looks like its a spritekit bug in SKPhysicsBody (I would guess it is being retained within bodyWithPolygonFromPath but not released).

Hmm... I'm really not sure what is going on here. However, would it be possible to try it using UIBezierPath to create the path instead.

Just to test it...

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);

Would become...

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];

Just to see if that stops the leaks. If so... keep it :D

If you have to use the path multiple times then you can keep a reference to it so you can lazily load it and then only have to load it once.

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