Are Nodes freed automatically if nothing references them?

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

I read everywhere that References are ref-counted, and get freed when they are no longer referenced, but Nodes should be free manually.
However, running the following code and viewing it in task manager, I see that memory does not increase. Why is that? Are Nodes freed?

extends Node

class Thing:
	var arr : Array = []
	func _init():
		for i in 1000 * 1000:
			arr.push_back(i)

func _process(delta):
	var thing = Thing.new()
:bust_in_silhouette: Reply From: imjp94

Nodes must always be freed manually, as Node class inherits from Object not Reference.

And, inner class is always inherits from Reference by default, that’s why the test you have done doesn’t cause memory leak, since class Thing is inner class.
To get the test as expected, you have to explicitly extends from Object(class Thing extends Object)

Thanks, the thing I missed was "By default, all classes that don’t define inheritance extend Reference. "
(That doesn’t only mean inner classes though imo, it means classes which do not have “extends something”, am I right?)

KijeviGombooc | 2020-12-27 13:03

Yes, this rules apply to any class.

imjp94 | 2020-12-27 13:13