what happens to object not added as child

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lowpolygon

Just suddenly occurs to me, if I instance an object without add it as a child to a node
what happens to that instanced object after that function finished running ?

:bust_in_silhouette: Reply From: Dlean Jeans

If it’s stored as a local variable then it will be gone.
If stored as a class property then it will remain there still.

“Gone”, as in “memory leak” :wink:

Zylann | 2019-07-03 12:37

Yep, you’re right, “gone” as references but dozens of MBs can be leaked per second in _process.

Dlean Jeans | 2019-07-03 14:54

:bust_in_silhouette: Reply From: hilfazer

Nothing will happen, Object will continue to exist causing a memory leak.

SceneTree takes care of lifetime of Nodes that are inside it. Nodes outside of tree need to be free()d manually.

There is an object that is reference counted, thus have automatic memory management. It’s Reference.
Node doesn’t inherit Reference.