I’ve a util helper that provides physics physique to a node:
@discardableResult
public static func addPhysicsBody(to node: SCNNode, sort: SCNPhysicsBodyType) -> SCNPhysicsBody {
// Right here I exploit SCNPhysicsShape(node:) API
let form = SCNPhysicsShape(node: node)
let physique = SCNPhysicsBody(sort: sort, form: form)
node.physicsBody = physique
return physique
}
There appears to be a retain cycle. Even when I take away the node from guardian, the node remains to be in reminiscence.
Nonetheless, if I modify the code to:
@discardableResult
public static func addPhysicsBody(to node: SCNNode, sort: SCNPhysicsBodyType) -> SCNPhysicsBody {
// Right here I modify to SCNPhysicsShape(geometry:) API
let form = SCNPhysicsShape(geometry: node.geometry!)
let physique = SCNPhysicsBody(sort: sort, form: form)
node.physicsBody = physique
return physique
}
This solves the retain cycle – after node is faraway from guardian, the node is just not in reminiscence anymore.
I think the retain cycle is brought on by SCNPhysicsShape(node: node)
API (https://developer.apple.com/documentation/scenekit/scnphysicsshape/init(node:choices:)), the place the node retains physics physique, which retains form, which retains the node.
Nonetheless, I really feel dumbfounded that apple did not understand such an apparent retain cycle, which makes me doubt myself. Did I exploit the API incorrect?