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 . ///