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

await results in GDScriptFunctionState memory leaks #74449

Open
MikeSchulze opened this issue Mar 5, 2023 · 5 comments
Open

await results in GDScriptFunctionState memory leaks #74449

MikeSchulze opened this issue Mar 5, 2023 · 5 comments

Comments

@MikeSchulze
Copy link

Godot version

v4.0.stable.official [92bee43]

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 #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

@MikeSchulze MikeSchulze changed the title await results in GDScriptFunctionState memory leaks await results in GDScriptFunctionState memory leaks Mar 5, 2023
@kleonc
Copy link
Member

kleonc commented Mar 5, 2023

The same in the current master [5dccc94].

@MikeSchulze
Copy link
Author

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

@kleonc
Copy link
Member

kleonc commented May 1, 2023

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.

@adamscott adamscott self-assigned this May 1, 2023
@MikeSchulze
Copy link
Author

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

@MikeSchulze
Copy link
Author

After more than one year, this bug is still open ;(

MikeSchulze added a commit to MikeSchulze/gdUnit4 that referenced this issue Nov 21, 2024
# Why
Running tests via CMD line shows a lot of memory leaks at program exit.

# What
- fixed releasing of all singletons
- `func_assert` has problems with lambdas when using inside
`timer.timeout.connect`, converted lambda into function
- Handling of stored asserts in the thread context results in
inconsistency during cleanup
- fixed cleanup on `GdUnitCommandHandlerTest`


## Finally, I have reduced most of the memory leaks nodes, but there are
still `GDScriptFunctionState` orphaned nodes that I can't solve because
these are handled internally by Godot see
[74449](godotengine/godot#74449)

```
Statistics: | 947 tests cases | 0 error | 0 failed | 1 flaky | 13 skipped | 0 orphans |

Executed test suites: (100/104), 4 skipped
Executed test cases: (934/947), 13 skipped
Total time:        3min 0s 409ms
Open Report at: file:///home/runner/work/gdUnit4/gdUnit4/reports/report_1/index.html
Exit code: 0
----------------------------------------------------------------
Cleanup singletons ["GdUnitThreadManager", "GdUnitDefaultValueDecoders", "GdUnitCommandHandler"]

	Unregister singleton 'GdUnitThreadManager'
	Free singleton instance 'GdUnitThreadManager:<Object#507678557642>'
	Successfully freed 'GdUnitThreadManager'

	Unregister singleton 'GdUnitDefaultValueDecoders'
	Free singleton instance 'GdUnitDefaultValueDecoders:<Object#509540832395>'
	Successfully freed 'GdUnitDefaultValueDecoders'

	Unregister singleton 'GdUnitCommandHandler'
	Free singleton instance 'GdUnitCommandHandler:<Object#3858659025580>'
	Successfully freed 'GdUnitCommandHandler'
----------------------------------------------------------------
Finallize .. done
Finallize ..
-Orphan nodes report-----------------------
Finallize .. done
XR: Clearing primary interface
XR: Removed interface "Native mobile"
XR: Removed interface "OpenXR"
WARNING: ObjectDB instances leaked at exit (run with --verbose for details).
     at: cleanup (core/object/object.cpp:2327)
Leaked instance: GDScriptFunctionState:9223373291404658414
Leaked instance: GDScriptFunctionState:92233732947[6010](https://github.com/MikeSchulze/gdUnit4/actions/runs/11956449331/job/33331231410?pr=599#step:4:6018)1646
Leaked instance: GDScriptFunctionState:9223373292545509197
Leaked instance: GDScriptFunctionState:9223373291673093970
Leaked instance: GDScriptFunctionState:9223373293719914330
Leaked instance: GDScriptFunctionState:9223373292881053539
Leaked instance: GDScriptFunctionState:9223373296521709422
Leaked instance: GDScriptFunctionState:9223378085393468557
Leaked instance: GDScriptFunctionState:9223382060754801221
Leaked instance: GDScriptFunctionState:9223373293753472331
Leaked instance: GDScriptFunctionState:9223377142497156399
Leaked instance: GDScriptFunctionState:9223378085359924447
Leaked instance: GDScriptFunctionState:9223382060788375283
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: test_case1 (static: 0, total: 1)
Orphan StringName: _validate_callback (static: 0, total: 1)
Orphan StringName: await_millis (static: 0, total: 5)
Orphan StringName: test_timeout_single_yield_wait (static: 0, total: 1)
Orphan StringName: test_timeout_2s (static: 0, total: 1)
Orphan StringName: _execute (static: 0, total: 1)
Orphan StringName: test_timeout_4s (static: 0, total: 1)
Orphan StringName: timeout (static: 2, total: 8)
Orphan StringName: cb_is_equal (static: 0, total: 2)
Orphan StringName: test_timeout_long_running_test_abort (static: 0, total: 1)
Orphan StringName: test_timeout_and_assert_fails (static: 0, total: 1)
StringName: 11 unclaimed string names at exit.
Run tests ends with 0
```
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