Skip to content

Commit 972bd09

Browse files
authored
Fixed a memory leak issue related to event handlers
Event handlers in the HoverLight weren't being unsubscribed On Disconnected.
1 parent 2abc65c commit 972bd09

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

AIDevGallery/Controls/HomePage/Header/Lights/HoverLight.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ private void TargetElement_PointerExited(object sender, PointerRoutedEventArgs e
9292

9393
protected override void OnDisconnected(UIElement oldElement)
9494
{
95+
// Unsubscribe event handlers to avoid retaining references and leaking the light or target element
96+
oldElement.PointerMoved -= TargetElement_PointerMoved;
97+
oldElement.PointerExited -= TargetElement_PointerExited;
98+
9599
// Dispose Light and Composition resources when it is removed from the tree
96100
RemoveTargetElement(GetId(), oldElement);
97101
CompositionLight.Dispose();
@@ -104,4 +108,4 @@ protected override string GetId()
104108
{
105109
return Id;
106110
}
107-
}
111+
}

0 commit comments

Comments
 (0)