From 6597e40e9d831a4cf448df02bfc29eb87498adba Mon Sep 17 00:00:00 2001 From: Anonymous Date: Tue, 16 Dec 2025 17:36:55 +0100 Subject: [PATCH] Fix some leaked managed shell (#1095) --- .../InteractionModes/InteractionModeManager.cs | 11 +++++++++++ .../BoundsControl/BoundsCalculator.cs | 2 ++ .../Interop/UGUIInputAdapter.cs | 13 +++++++++++++ 3 files changed, 26 insertions(+) diff --git a/org.mixedrealitytoolkit.input/InteractionModes/InteractionModeManager.cs b/org.mixedrealitytoolkit.input/InteractionModes/InteractionModeManager.cs index 292502186..be1684de1 100644 --- a/org.mixedrealitytoolkit.input/InteractionModes/InteractionModeManager.cs +++ b/org.mixedrealitytoolkit.input/InteractionModes/InteractionModeManager.cs @@ -319,6 +319,17 @@ private void Awake() InitializeInteractionModeDetectors(); } + /// + /// A Unity event function that is called when the script component has been destroyed. + /// + private void OnDestroy() + { + if (InteractionManager != null) + { + InteractionManager.interactorRegistered -= OnInteractorRegistered; + } + } + /// /// A Unity Editor only event function that is called when the script is loaded or a value changes in the Unity Inspector. /// diff --git a/org.mixedrealitytoolkit.spatialmanipulation/BoundsControl/BoundsCalculator.cs b/org.mixedrealitytoolkit.spatialmanipulation/BoundsControl/BoundsCalculator.cs index f23d1eed2..10e1b700a 100644 --- a/org.mixedrealitytoolkit.spatialmanipulation/BoundsControl/BoundsCalculator.cs +++ b/org.mixedrealitytoolkit.spatialmanipulation/BoundsControl/BoundsCalculator.cs @@ -100,6 +100,8 @@ internal static Bounds CalculateBounds( finalBounds.Encapsulate(root.InverseTransformPoint(totalBoundsCorners[i])); } + totalBoundsCorners.Clear(); + childTransforms.Clear(); // Avoid keeping reference to Unity objects to avoid "Leaked Memory Shell" return finalBounds; } diff --git a/org.mixedrealitytoolkit.uxcore/Interop/UGUIInputAdapter.cs b/org.mixedrealitytoolkit.uxcore/Interop/UGUIInputAdapter.cs index 26723be67..f38562598 100644 --- a/org.mixedrealitytoolkit.uxcore/Interop/UGUIInputAdapter.cs +++ b/org.mixedrealitytoolkit.uxcore/Interop/UGUIInputAdapter.cs @@ -164,6 +164,19 @@ protected override void OnDisable() } } + /// + /// A Unity event function that is called when the script component has been destroyed. + /// + protected override void OnDestroy() + { + base.OnDestroy(); + if (InteractionManager != null) + { + InteractionManager.interactorRegistered -= OnInteractorRegistered; + InteractionManager.interactorUnregistered -= OnInteractorUnregistered; + } + } + /// /// Called when a an is registered with a Unity . ///