How to manage the memory of node that has not added to the scene tree?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By alexzheng
:warning: Old Version Published before Godot 3 was released.

For nodes in the following situations
1, create a node A in code and do not added to the scene tree, just hold a reference to it
2,define node A in the scene file, but removed from parent after instanced, just hold a reference to it

When the scene that contains node A exit tree, node A maybe is added to scene tree or may be not.
If node A is added to the scene, it will free automatically, however, if it’s not added to the scene tree, will it required to free it manually?

:bust_in_silhouette: Reply From: volzhs

if node is added to scene tree, it will be freed when scene is freed, like changed to another scene.
but if node is not added, you need to free it manually, or there will be memory leak.
you can do it by node.free() when needed.