ihsoft / KSPDev_Utils

Tools set for Kerbal Space Program mods developemnt
Other
3 stars 0 forks source link

Memory Leak: GuiScale's destructor will never be called because the GameEvent system has a reference to it #14

Open JonnyOThan opened 1 year ago

JonnyOThan commented 1 year ago

The event handler registered here: https://github.com/ihsoft/KSPDev_Utils/blob/7c2be521508f91562b30c7e4eec64b389e4bdc8b/Source/GUIUtils/GuiScale.cs#L81

means that the GameEvent system will be holding onto a reference to this object, which means that it'll never be garbage collected, which means that the destructor will never be called to unhook the GameEvent handler. I noticed this in someone's logs after they enabled KSPCF's memory leak tracking:

ihsoft commented 1 year ago

While it's indeed a bug, I wonder why so many subscribers. This class is supposed to be used as static or session. Which mods do you have installed?

JonnyOThan commented 1 year ago

Sorry, this was someone else’s log that I was investigating. I really should have uploaded it! I’ll see if I can find it.

I did do a GitHub search and the only users of that class I was able to find are KIS and KAS (unless it’s called indirectly somewhere maybe).

btw you need to turn on the extra memory leak tracking options in kspcf’s settings.cfg to see the exact subscriber lists.