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

Hanging await leaks memory, throws error (aka resume after free) #72629

Closed
vpellen opened this issue Feb 2, 2023 · 2 comments
Closed

Hanging await leaks memory, throws error (aka resume after free) #72629

vpellen opened this issue Feb 2, 2023 · 2 comments
Labels

Comments

@vpellen
Copy link

vpellen commented Feb 2, 2023

Godot version

v4.0.beta17.official [c400205]

System information

Windows 10

Issue description

In spite of the fact that this issue is, I believe, one of the most infamous issues plaguing GDScript at the current time, I couldn't find an existing ticket that references the issue explicitly.

Here's the core of it: If you await a signal that has a longer lifetime than the object containing the coroutine itself, and then free the object before resuming the coroutine, you get a memory leak if the signal is never emitted, and an error if it is. There are a number of ways to interpret why this happens, but the core of it seems to be that freeing an object does not appear to disconnect any GDFunctionState instances that depend on the object itself. I experimented with a release build, and while it doesn't appear to cause a crash, I think it's fair to say that ignoring an error that arguably shouldn't exist is not a graceful solution. There may also be other side effects I'm not actually aware of.

There are ways of working around this, but they're all fickle, and the quintessential coroutine example of:

await get_tree().process_frame

is one of the fastest ways to trip over the problem.

Steps to reproduce

Stick the following in your node of choice:

func _ready():
	queue_free()
	await get_tree().process_frame

Minimal reproduction project

N/A

@vpellen
Copy link
Author

vpellen commented Feb 3, 2023

Possibly fixed by #65910?

@KoBeWi
Copy link
Member

KoBeWi commented Feb 3, 2023

And duplicate of #24311 ;)

@KoBeWi KoBeWi closed this as not planned Won't fix, can't repro, duplicate, stale Feb 3, 2023
@KoBeWi KoBeWi added the archived label Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants