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

Class with a member variable with its own type causes a leak #47770

Open
mortarroad opened this issue Apr 10, 2021 · 1 comment
Open

Class with a member variable with its own type causes a leak #47770

mortarroad opened this issue Apr 10, 2021 · 1 comment

Comments

@mortarroad
Copy link
Contributor

Godot version:
3.3.rc8
(master seems to be unaffected)

Issue description:
If a class references itself in a variable type, it causes a leak.
Probably related:
#16959
#45986
#46467

Steps to reproduce:
Attach the following script to a node and run.

extends Spatial

class A:
	var a: A

The log is as follows:

ERROR: ~List: Condition "_first != __null" is true.
   At: ./core/self_list.h:112
ERROR: ~List: Condition "_first != __null" is true.
   At: ./core/self_list.h:112
WARNING: cleanup: ObjectDB instances leaked at exit (run with --verbose for details).
     At: core/object.cpp:2132
Leaked instance: GDScript:1192 - Resource path:
Leaked instance: GDScriptNativeClass:550
Hint: Leaked instances typically happen when nodes are removed from the scene tree (with `remove_child()`) but not freed (with `free()` or `queue_free()`).
Orphan StringName: ::0::A._init
Orphan StringName: Reference
Orphan StringName: GDScriptNativeClass
Orphan StringName: a
Orphan StringName: res://scene.gd
Orphan StringName: _init
Orphan StringName: GDScript
StringName: 7 unclaimed string names at exit.

Minimal reproduction project:
bug_unfreed.zip

Run, then close the running project.

@stengun
Copy link

stengun commented May 3, 2021

Godot Version: 3.3 stable

I'm affected with a similar issue (I suppose is basically the same as this one so I avoid to spawn a new issue for this), in which the leak happens if you cast a variable to the same class instead.
We have a scene LeakTest.tscn with an attached script LeakTest.gd

class_name LeakTest

func something() -> void:
    var helo = load("res://LeakTest.tscn").instance() as LeakTest

This gives leaked instance of LeakTest.gd upon closing the program. With the same code, if I remove the cast it works correctly. I also noted that if you specify return values (or function parameters) typed with the same custom class it works fine and no leaks happens.

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

3 participants