The ListBox has children that have subscriptions. Let's say ListBox has StackPanel and StackPanel has a Button that has a subscription.
After using StackPanel, I want to remove StackPanel from the ListBox.
// There is a ListBox named "list".
StackPanel stack = new StackPanel();
Button button = new Button();
RoutedEventHandler eventHandler = (s, e) => { ... };
button.Click += eventHandler;
stack.Children.Add(button);
list.Items.Add(stack);
...
// Now I want to remove StackPanel.
// Should I do this before removing: "button.Click -= eventHandler;"?
list.Items.Remove(stack);
Should I unsubscribe Button before removing StackPanel from the ListBox (to avoid memory leaks)? Or is it enough to remove StackPanel from the ListBox so that the child subscriptions (in this case, Button) disappear and the garbage collector can easily collect them? Thank you.