memory leak with get_tree().reload_current_scene()

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dblue

When I do get_tree().reload_current_scene() it doesn’t reset any of the scene instances I’ve created.

Is there no way to do an easy clean reset of the game?
Do I really need to keep track of every single scene instance I create in order to free them when I reset? This is a nightmare for anyone doing procedural generation.

edit: nevermind I’m dumb it’s because I was creating the instance in a AutoLoad singleton script, that’s why the instance wasn’t clearing when I tried to reload the scene.

I’ve wondered about this myself. I use:


While it works, and the scene changes, I do worry about memory allocation each time the scene changes. For example, I see a lot of tutorials suggesting the best way to reset a game level is by reloading the scene. I have to believe that this has a negative impact on memory… unless there’s some really fancy magic going on inside Godot.

Would be interested to see if there are more efficient ways to handle this. Perhaps by using a state machine and resetting to default data without actually changing any scenes? I’m not sure.

i_love_godot | 2019-01-24 01:04