Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"WARNING: ObjectDB instances leaked at exit" on initiating Node2d object with c# #44226

Closed
Szesan opened this issue Dec 9, 2020 · 5 comments
Closed

Comments

@Szesan
Copy link

Szesan commented Dec 9, 2020

Godot version: 3.2.3 - stable_mono_win64

OS/device including version: Windows 10 Home PC

Issue description:

  • Tried instantiating a Node2d object from code:

var newNode = new Node2D();

The above command triggers the following error:

WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
at: cleanup (core/object.cpp:2135)

Steps to reproduce:

    • Create new project
    • Create main scene
    • Insert the above command var newNode = new Node2D(); in the _Ready() method

Minimal reproduction project:

TestLeak.zip

@Szesan
Copy link
Author

Szesan commented Dec 9, 2020

I've figured out that if I connect the instance to the SceneTree by
AddChild(newNode); for example, the leak is gone. But I think there should be a garbage collection that picks up unparrented nodes on exit.

@pouleyKetchoupp
Copy link
Contributor

This warning makes sense, it's not a bug.

Nodes are not automatically freed on exit, unless they are added to the scene, for example by using add_child(newNode); in your case.

On the other hand, Resources or any class that inherits from Reference use a ref counting system and are freed automatically when not used.

Documentation:
https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_basics.html?#memory-management

Note for contributors:
Maybe the documentation could be clearer on this aspect? It doesn't say anything about Nodes not being managed automatically unless added to the scene.

@Szesan
Copy link
Author

Szesan commented Dec 9, 2020

Documentation:
https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_basics.html?#memory-management

Thanks, good to know. Coming from a .net background I assumed that there is garbage collection.

@akien-mga
Copy link
Member

Indeed that's expected behavior. AddChild(newNode); solves the issue by making the new Node part of the scene tree and thus freed together with the scene tree when you close the game.

Maybe the documentation could be clearer on this aspect? It doesn't say anything about Nodes not being managed automatically unless added to the scene.

I opened an issue for this:
godotengine/godot-docs#4877

@Karmavil
Copy link
Contributor

This was very helpful. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants