godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.13k stars 21.19k forks source link

`await` results in `GDScriptFunctionState` memory leaks #74449

Open MikeSchulze opened 1 year ago

MikeSchulze commented 1 year ago

Godot version

v4.0.stable.official [92bee43ad]

System information

Windows 10

Issue description

Using await results in memory leak.

I got a lot of orphan nodes at exit after execution my test coverage (using GdUnit4). The tests uses some stuff around timeouts and await for signals and function results.

I've boiled it down so far, and it looks like a simple "await get_tree().process_frame". already suffices to get orphan nodes,

Leaked instance: GDScriptFunctionState:-9222494076819996251
Hint: Leaked instances typically happen when nodes are removed from the scene tree (with `remove_child()`) but not freed (with `free()` or `queue_free()`).

I found this issue https://github.com/godotengine/godot/issues/57126, but it is already closed.

And also a lot of orphan StringName are found, i guess this is already adressed.

Steps to reproduce

execute the attached scene by

Godot.exe --verbose -d res://Orphans.tscn

XR: Clearing primary interface
XR: Removed interfaceNative mobile
XR: Removed interfaceOpenXR
WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
     at: cleanup (core/object/object.cpp:1982)
Leaked instance: GDScriptFunctionState:-9222496825599065104
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: OP_MODULE
....

Minimal reproduction project

orphan_await.zip

kleonc commented 1 year ago

The same in the current master [5dccc940e73d39a1ac4f3d64ccc92373e6609add].

MikeSchulze commented 1 year ago

Hello, what is the current status on the subject? The amount of orphaned objects is smoothly overwhelming ;)

kleonc commented 1 year ago

what is the current status on the subject?

I can see/tell as much as you do: no one said anything in here, no linked PR / other issues. So I'd guess no one investigated this. I'll put a link at the contributor's chat, maybe someone will get interested.

MikeSchulze commented 1 year ago

it sill occurs on v4.1.stable.official [970459615]