Im from the ideas here, SceneKit imposes a memory and Im just starting. Im displaying SNCNodes
which are stored in arrays, so I can separate the components of the molecule from the animation. These trees model molecules, of which I will ultimately have, perhaps, 50 to display, say, one per “chapter”. The problem is that when I move to another chapter, the molecules from the previous chapters are stored in memory.
Molecule nodes are trees of child nodes. About half of the nodes are empty containers for orientation. Otherwise, geometry SCNPrimitives
(spheres, capsules and cylinders). Each geometry has a mirror and diffuse material
, consisting of UIColor
not used textures.
When the application first loads, these molecules are created from code and archived into a dictionary. Then, and at subsequent downloads, the archived dictionary is read into the local dictionary for use by VC. (Im shortening the security features in this post for brevity.)
moleculeDictionary = Molecules.readFile() as! [String: [SCNNode]]
When a chapter wants to map a molecule, it invokes a specific function that loads the necessary components for a given molecule from the local dictionary into local properties SCNNode
.
var atomsNode_1 = SCNNode()
var atomsNode_2 = SCNNode()
. . .
func lysozyme() {
. . .
components = moleculeDictionary["lysozyme"]
atomsNode_1 = components[0]
baseNode.addChildNode(atomsNode_1)
atomsNode_2 = components[2]
baseNode.addChildNode(atomsNode_2)
. . .
}
Before the next molecule is displayed, I call the "clear" function:
atomsNode_1.removeFromParentNode()
atomsNode_2.removeFromParentNode()
. . .
When I research tools, most of the bloated memory is 32 kbytes of chunks called C3DMeshCreateFromProfile
and 80 kB chunks C3DMeshCreateCopyWithInterleavedSources
.
, , NSKeyedUnarchiver
. , , .
, , .
Ive atomsNode_1
, . . Ive , ,
atomsNode_1.enumerateChildNodesUsingBlock({
node, stop in
node.removeFromParentNode()
})
, , , , . !
, , [SCNNode]
, . , , . , . , , .