forked from godotengine/godot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
As you may know Godot does not use a garbage collector and thanks to that there are no collection stalls. Instead, it uses reference counting. While Godot resoucres are designed so its extremely hard to have reference cycles, it is possible on the script side to have a reference cycle and thus leak script resources. Godot will report these leaked objects on exit, but sometimes it can be hard to find and track them down. This PR adds a cycle breaker. It is used like this: ```GDScript get_tree().break_reference_cycles() ``` The cycle breaker basically tracks and tags anything connected to the scene tree and engine singletons. It does this very quickly, so you can call this function during loading screen, game exit or pauses. It has a few modes in which it functions: * Script only: This only tracks cycles in script classes not connected to the scene tree and singletons and breaks them. This mode should be safe to use. * All objects: This tracks any object not connected to the scene tree and singletons and clears all resources properties on them to clear cycles. This is not advisable to use unless you know what you are doing. Additionally, the type of tagging can be customized: * Only scan resources, do not get into containers: This is the fastest mode, but if you have scripts referenced from containers (array or dictionary) it will miss them. * Containers: This mode will go into containers. It is more effective, but slower. Finally, there is the option to print what was collected. This is intended in case you want to debug a leak and resolve it instead of relying on the cycle breaker. This function returns how many cycles were broken, which may add in debugging and CI tasks. TODO: - [ ] I think some GDScript globals and static variables are not being tracked, but need to ask the GDScript team about this. - [ ] Some singletons or global objects may not be tracked or may be too hard to track. Possibly may be good to simply add them to an ignore list (via some virtual function to ignore them on tagging). - [ ] Maybe warn the user if there are threads running (likely via WorkerThreadPool query). While the ObjectID access is thread safe, this function shoud ideally be run after joining all threads. Feedback welcome!
- Loading branch information
Showing
22 changed files
with
355 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.