We also took another pass at native resource leaks, particularly around shutdown. After some previous attempts we were still leaking native resources, and we've fixed a lot of them. Tracking these down also surfaced a handful of general runtime leaks, which we fixed along the way.
Hopefully, this will also reduce the large amount shutdown crashes most of us have been experiencing.
We also added a managed leak tracker that reports and force-destroys leaked resources at shutdown, enable resource_leak_tracking for full allocation callstacks and report them to us.
[...]
NativeResourceCache: Resource still alive during shutown,
which can indicate a leak: Material [10022664158783386085] model (model)
will be force destroyed.
NativeResourceCache: Allocation callstack:
at Sandbox.Material.FromNative(IMaterial native, String name)
at Sandbox.Material.Create(String materialName, String shader, Boolean anonymous)
at MaterialLoader..cctor()
at System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(RuntimeTypeHandle type)
at Sandbox.ReflectionUtility.RunAllStaticConstructors(Assembly asm)
at Sandbox.Mounting.Directory.LoadAssemblies()
at Sandbox.Engine.Bootstrap.PreInit(CMaterialSystem2AppSystemDict appDict)
at Sandbox.AppSystem.InitGame(AppSystemCreateInfo createInfo, String commandLine)
at Sandbox.GameAppSystem.Init()
at Sandbox.AppSystem.Run()
at Sandbox.Launcher.Main()
at Sandbox.Program.Launch()
at Sandbox.Program.Main()
NativeResourceCache: Total leaks: 3