objective-c - SKPhysicsBody bodyWithPolygonFromPath 内存泄漏

标签 objective-c memory-leaks game-physics sprite-kit skphysicsbody

在创建具有自定义形状的 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 工具包中的错误。您将不得不等待修复。

关于objective-c - SKPhysicsBody bodyWithPolygonFromPath 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20134891/

相关文章:

导航时 Javascript 内存泄漏

c# - 在 C#/XNA 中使用通用函数进行碰撞检测

ios - 如何将 Sprite Kits 物理值转换为绝对点值?

objective-c - CGContextStrokePath 在 iOS > 5 中触发 EXC_BAD_ACCESS

iphone - 重复符号错误xcode iphone

c++ - MSVC _Crt* 宏在 RAII 代码中使用不安全

javascript - 当一个元素被javascript中的另一个元素触摸时,如何更改该元素的位置?

iOS:有没有办法获取 View 中每个元素的背景颜色?

ios - 在越狱设备上以编程方式发送短信

java - 在循环中创建位图时发生内存泄漏