However, it does not state whether I need to clean up anything and why. I expect that very often developers just do get_tree().quit() and that’s it. But recently I noticed ‘leaked resources’ warnings in the console and now I wonder:
Do I need to call queue_free() on each node before quitting?
Do I need to implement _notification on all my nodes to cleanup on NOTIFICATION_WM_CLOSE_REQUEST ?
Do I actually need to aim for 0 leaked-warnings in console? If yes, then why?
My expectation would be that quit() transitively calls queue_free() on all nodes (or on scene root which, as I expect, the same)
Nope, you do not need to use anything before quit, otherwise NOTIFICATION_WM_CLOSE_REQUEST is when you quitting the game, you can run codes in _notification like you made a code editor where your codes is unsaved, so when user quit the editor, it will not quit and a message shows that do you sure to quit? All you can do in _notification. Like I have made this code editor using Godot
Without details on your actual project it’s hard to tell what isn’t cleaned up, do you have circular references for example? They will cause leaks, but I don’t get leaks on normal use so this sounds like a project specific issue
You don’t need to clean up anything explicitly assuming you close down safely and if you don’t have incorrect resource use
I have object pools - and I assume that I maybe have to clear their internal arrays of instantiated Nodes to have no leaks? And again, one of the main questions is:
Do I need to worry about leak-warnings? Do they mean I’m open to sudden game crashes and, therefore, I’d better fix all these leak-warnings? Or maybe they are not “critical”, meaning, the resources will be cleaned up for me on actual exit anyway?
UP
Some entities do have circular references (e.g. a creature knows its spawner and a spawner knows all its creatures). Do I need to null-ify these references on exit?
Depends, if it happens when the engine closes down normally they are relevant to care about, if they’re data loaded in scenes and on scene change, that would mean leaks when loading different scenes, causing memory to run out gradually, so it’s not always critical, but you shouldn’t ignore them if you can fix them and they’re due to your code