You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Turns out that the vast majority of memory leaks are caused by objects subscribing to GameEvents and never removing them, causing those objects and anything they reference to never be garbage collected.
I've implemented some mechanisms in KSPCF to automatically clean up such leaks when they originate from destroyed instances of UnityEngine.Object derivatives (this notably covers PartModule, VesselModule, KSPAddon and KSPScenario derivatives).
However, there is no way to do such a thing for regular classes, so I've also implemented some debugging tools that allow to detect those leaks.
GameEvents related leaks are not only an issue from a memory standpoint.
All the dead or duplicate delegates are still called, which :
Slows down overall event processing
Can cause hard to track down issues by executing code on instances that are not supposed to exist anymore.
While casually testing KSPCF on an install with CC installed, I found the following GameEvents leaks :
UnityEngine.Object derivatives leaks :
Removed a onGUIMessageSystemReady GameEvents callback owned by a destroyed ContractConfigurator.ScienceReporter instance
Removed a OnScienceRecieved GameEvents callback owned by a destroyed ContractConfigurator.ScienceReporter instance
I didn't actually check the CC code for other cases, so keep in mind that there might be false positives in that list. I also didn't do extensive tests, so it is quite possible I missed other leaks.
The TitleTracker class related leaks are quite severe, with 200+ delegates leaked per scene switch in a game with not a lot going on. The pattern of removing GameEvents in a finalizer doesn't work, as the GameEvent subscription will prevent the object from ever be garbage collected in the first place :
I've been doing some work in KSPCF to tackle KSP memory leaks.
Turns out that the vast majority of memory leaks are caused by objects subscribing to GameEvents and never removing them, causing those objects and anything they reference to never be garbage collected.
I've implemented some mechanisms in KSPCF to automatically clean up such leaks when they originate from destroyed instances of
UnityEngine.Object
derivatives (this notably coversPartModule
,VesselModule
,KSPAddon
andKSPScenario
derivatives).However, there is no way to do such a thing for regular classes, so I've also implemented some debugging tools that allow to detect those leaks.
GameEvents related leaks are not only an issue from a memory standpoint.
All the dead or duplicate delegates are still called, which :
While casually testing KSPCF on an install with CC installed, I found the following GameEvents leaks :
UnityEngine.Object derivatives leaks :
Other classes leaks :
I didn't actually check the CC code for other cases, so keep in mind that there might be false positives in that list. I also didn't do extensive tests, so it is quite possible I missed other leaks.
The
TitleTracker
class related leaks are quite severe, with 200+ delegates leaked per scene switch in a game with not a lot going on. The pattern of removing GameEvents in a finalizer doesn't work, as the GameEvent subscription will prevent the object from ever be garbage collected in the first place :ContractConfigurator/source/ContractConfigurator/Util/TitleTracker.cs
Lines 73 to 77 in a20bfdf
The text was updated successfully, but these errors were encountered: