What is the best way to find unfreed resources when game exits?

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

Having some trouble finding a lost scene or script (or two) that I hadn’t properly freed before exiting the game.

Was wondering if anyone had any debugging tips for finding them, since the exit will crash and the console says nothing.

Normally this is not something that should cause a problem, Godot manage the memory for you. Still, it should not crash, just create memory leaks. Are you able to reproduce the issue with a minimal project?

BraindeadBZH | 2018-03-27 20:41

Unfortunately, I’ve been as successfully at recreating it as finding the resources causing it.

It seems to be something to do when a character fires a bunch of bullets. Afterwards if you try to close the program it will hang up and crash.

I thought I would ask if anyone knows of a way to inspect resources at exit in a debug build, because otherwise I’ll have to rewrite a few thousand lines of code, rebuilding along the way.

avencherus | 2018-03-27 21:10

:bust_in_silhouette: Reply From: Hammer Bro.

In a command line, navigate to the folder which contains your project.godot file.

Then, still via that command prompt, launch the Godot executable with the ‘-v’ parameter.

If executed correctly, Godot will automatically start running your game (regardless of whether you have an Editor instance open) and it will include debug output. This includes a moderate amount of information about leaked resources on exit.

It won’t tell you where the leak occurred but it will tell you what’s leaking.

:bust_in_silhouette: Reply From: jbodah

I found that you can enable logging and enable the verbose flag (my releases were having issues that my dev env wasn’t). Note GDScript is not garbage collected per the docs

Logging and verbose stdout mode can be enabled by searching Project Settings. If you are debugging a release then you can export with debug mode in the export panes. The log file can be found by Project > Open Project Data Folder

:bust_in_silhouette: Reply From: avencherus

Those answers given are good suggestions for debugging verbosely from the console, and useful for finding most resource leaks.

In the case of this old issue there wasn’t anything I could find in the output, and had to resolve it be attaching a debugger to the source and doing a lot of probing to track down the offending scripts. Eventually the problem reoccurred and hit one of my break points. I don’t remember the exact issue too well anymore.