创建具有自定义形状的Sprite Kit物理实体时,我有一个奇怪的内存泄漏。这是我的实现的样子:
CGFloat offsetX = self.frame.size.width * self.anchorPoint.x;
CGFloat offsetY = self.frame.size.height * self.anchorPoint.y;
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 4 - offsetX, 3 - offsetY);
CGPathAddLineToPoint(path, NULL, 66 - offsetX, 3 - offsetY);
CGPathAddLineToPoint(path, NULL, 35 - offsetX, 57 - offsetY);
CGPathCloseSubpath(path);
self.physicsBody = [SKPhysicsBody bodyWithPolygonFromPath:path];
CGPathRelease(path);
一切都在
SKSpriteNode
方法内进行。在创建这样的主体之后,Instruments告诉我一些内存泄漏:Leaked object:
Malloc 32 Bytes
Size:
32 Bytes
Responsible Library:
PhysicsKit
Responsible Frame:
std::__1::__split_buffer<PKPoint, std::__1::allocator<PKPoint>&>::__split_buffer(unsigned long, unsigned long, std::__1::allocator<PKPoint>&)
CGPathRelease(path);
行是必需的-如果没有它,我会收到更多关于CGPath
的内存泄漏,这是可以理解的。当我改用此实现(出于测试目的)时:CGFloat radius = MAX(self.frame.size.width, self.frame.size.height) * 0.5f;
self.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:radius];
...一切正常,没有内存泄漏。我想知道这是Sprite Kit错误还是我做错了什么。
最佳答案
这是Sprite Kit中的错误。您将不得不等待修复。
关于objective-c - SKPhysicsBody bodyWithPolygonFromPath内存泄漏,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20134891/