Topic was automatically imported from the old Question2Answer platform.
Asked By
radubolovan
Hello,
Godot version:
2.1.4, 3.0. Both official releases.
Info:
I have an array (Array class) of objects that are dynamically created in a script using “push_back” member of the Array class. All objects are inherited from Node class or inherited from the Node class.
Sometimes I need to clear the array.
Question:
Should I manually erase children from memory by calling “queue_free()” for each node or the “clear” member of the Array class does that anyway?
Nodes are not reference-counted objects, so clearing the array will not free them. You should call queue_free before removing them from the array.
Thank you very much!
radubolovan | 2018-02-01 20:29
Are you sure?
I was pretty certain nodes, as most objects in godot, are referenced counted, meaning they would be destroyed if anything didn’t reference them.
Which in his case .clear would free them if they were not kept anywhere else or in the scene_tree.
Guilherme Furst | 2018-02-02 02:07
Nodes are not reference counted (they don’t inherit Reference). Their ownership model is based on the scene tree.
Resources, on the other hand, inherit Reference so if you clear an array of resources they can be freed automatically.