SKPhysicsBody bodyWithPolygonFromPath 内存泄漏 [英] SKPhysicsBody bodyWithPolygonFromPath memory leaks

查看:26
本文介绍了SKPhysicsBody bodyWithPolygonFromPath 内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建具有自定义形状的 Sprite Kit 物理实体时,我遇到了奇怪的内存泄漏.这是我的实现的样子:

I have a strange memory leaks when creating Sprite Kit physics bodies with custom shapes. This is how my implementation looks:

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 方法内部进行.仪器告诉我在创建这样的主体后发生了几次内存泄漏:

Everything is going on inside SKSpriteNode method. Instruments tells me about several memory leaks after creating such bodies:

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 的内存泄漏,这是可以理解的.当我使用此实现时(出于测试目的):

The CGPathRelease(path); line is necessary - without it I'm getting more memory leaks about CGPath which is understandable. When I'm using this implementation instead (for testing purposes):

CGFloat radius = MAX(self.frame.size.width, self.frame.size.height) * 0.5f;
self.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:radius];

...一切正常,没有内存泄漏.我想知道这是 Sprite Kit 的错误还是我做错了什么.

...everything is working well, without memory leaks. I wonder if this is Sprite Kit bug or I'm doing something wrong.

推荐答案

这是精灵套件中的一个错误.您将不得不等待修复.

This is a bug in sprite kit. You will have to wait for a fix.

这篇关于SKPhysicsBody bodyWithPolygonFromPath 内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆