admin管理员组文章数量:1315967
I have a util helper that adds physics body to a node:
@discardableResult
public static func addPhysicsBody(to node: SCNNode, type: SCNPhysicsBodyType) -> SCNPhysicsBody {
// Here I use SCNPhysicsShape(node:) API
let shape = SCNPhysicsShape(node: node)
let body = SCNPhysicsBody(type: type, shape: shape)
node.physicsBody = body
return body
}
There seems to be a retain cycle. Even if I remove the node from parent, the node is still in memory.
However, if I change the code to:
@discardableResult
public static func addPhysicsBody(to node: SCNNode, type: SCNPhysicsBodyType) -> SCNPhysicsBody {
// Here I change to SCNPhysicsShape(geometry:) API
let shape = SCNPhysicsShape(geometry: node.geometry!)
let body = SCNPhysicsBody(type: type, shape: shape)
node.physicsBody = body
return body
}
This solves the retain cycle - after node is removed from parent, the node is not in memory anymore.
I suspect the retain cycle is caused by SCNPhysicsShape(node: node)
API ((node:options:)), where the node retains physics body, which retains shape, which retains the node.
However, I feel dumbfounded that apple didn't realize such an obvious retain cycle, which makes me doubt myself. Did I use the API wrong?
本文标签: iosRetain cycle in SCNNode39s physicsBodyStack Overflow
版权声明:本文标题:ios - Retain cycle in SCNNode's physicsBody - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741985753a2408665.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论