C# Garbage Collector Behavior and Available Settings?

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

I am in the middle of converting a set of unit tests from Unity to Godot. Thus far the experience goes quite well and I was able to not only convert the pure C# stuff but also the 3D and UI test cases.

The big BUT in it all relates to testing finalizers. The finalizers are related to low level custom memory management and are very important. Also it works in Unity™.

Taking a deep dive and tracking the collection and finalization of managed objects in certain circumstances (in Debug version) using AtomicInt and WeakReference never yielded in finding a situations/patterns where a certain object (among up to billions of created and released objects) being predictably garbage collected and finalized.

It was not a matter of memory pressure, the latency mode, the time or deregistering + registering for finalizer etc.

So the big question goes:

How can I influence the Garbage Collector’s behavior of Godot Mono/C# using some startup/commandline/build settings and what other additional options / possibilities are there?


I don’t know how I can help you (considering I don’t use C#), but I would suggest seeking the help of some of the maintainers of the C# component of the engine. I would look at the repository for the Mono build scripts to see who’s contributed, most notably neikeq.

Ertain | 2021-09-02 05:34