0 votes

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()
in Engine by (145 points)

1 Answer

+2 votes
Best answer

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)

by (216 points)
selected by

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?)

Yes, this rules apply to any class.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories