I'm adding nodes to the scene and removing them once they leave the camera's field of view like this:
func removeUnusedBlocks() {
for child in mapNode.childNodes {
if !sceneView.isNode(child, insideFrustumOf: cameraNode) &&
child.worldPosition.z > playerNode.worldPosition.z {
child.removeFromParentNode()
blocks.removeFirst()
}
}
}
removeUnusedBlocks()
is being called successfully from func renderer(_ renderer: SCNSceneRenderer, didApplyAnimationsAtTime time: TimeInterval) { }
so I know the nodes are being removed from the scene.
However, the memory persists and increases! I see the fps decreasing rapidly, and Delegate (pink section) increasing.
I looked at the answers here about setting the geometry
to nil
and added this in the GameViewController.swift
:
deinit {
scene.rootNode.cleanup()
}
And after GameViewController.swift
closing braces:
extension SCNNode {
func cleanup() {
for child in childNodes {
child.geometry = nil
}
}
}
But it hasn't done anything. What can I do?