Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scene kit memory management using swift

I'm perplexed as to how I am to free up memory in scene kit using swift. Whenever I create an SCNNode from a collada file, It imports geometry, creates a physics object, and sets a material from a jpg file. This takes up 10 mb of ram when creating a new object for some reason (even though the files sizes are under 300k), but whatever. Whenever it is removed from the parent node, zero ram frees up, and I do not understand why. What code can I use to TRULY remove the object? I can't find any documentation on the subject. This is just a general question, so no code is needed here.

like image 755
tedesignz Avatar asked Aug 30 '15 09:08

tedesignz


2 Answers

So I found out what I needed to do was set the texture on my game objects to nil before removing them from the parent. Just as a general rule, I started setting all my textures to nil before deleting the node. Anyway, this solved my memory problem.

like image 118
tedesignz Avatar answered Nov 16 '22 01:11

tedesignz


If the node has a strong reference to it, ARC won't dealloc it. You can either switch the node's declaration to 'weak' property or set to nil any strong reference to the node. Change to weak fix due to the different behavior of 'strong' and 'weak'. While a object has a strong reference (simple var or let are automatically strong) it won't be taken out of memory, even if you use removeFromParent function.

like image 1
Samuel Cortez Avatar answered Nov 16 '22 03:11

Samuel Cortez