Skip to content

Fix TSTMstStgs settings callback leak#87

Open
appaKappaK wants to merge 1 commit into
JPLRepo:masterfrom
appaKappaK:pr/fix-tstmststgs-settings-callback-leak
Open

Fix TSTMstStgs settings callback leak#87
appaKappaK wants to merge 1 commit into
JPLRepo:masterfrom
appaKappaK:pr/fix-tstmststgs-settings-callback-leak

Conversation

@appaKappaK
Copy link
Copy Markdown

@appaKappaK appaKappaK commented May 16, 2026

Summary

Fixes #82

Fixes a KSPCF-reported memory leak where destroyed TSTMstStgs instances remain subscribed to GameEvents.OnGameSettingsApplied.

Root Cause

TSTMstStgs.Start() subscribes ApplySettings to GameEvents.OnGameSettingsApplied, but OnDestroy() was adding the callback again instead of removing it. Since TSTMstStgs is created for every scene, destroyed instances could accumulate as event callback owners across scene changes.

Changes

  • Unsubscribe ApplySettings from GameEvents.OnGameSettingsApplied in OnDestroy()
  • Clear TSTMstStgs.Instance when the destroyed object is the active singleton

Validation

Built and tested locally in KSP. After scene changes and roughly 2 hours of play, the previous KSPCF TarsierSpaceTech:TSTMstStgs / OnGameSettingsApplied warning did not reappear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak in TSTMstStgs

1 participant