Do I need to unsubscribe from an object's event before I point the object
variable to a new object?
I have a method that subscribes an event handler to the ListChanged event of
a list. The list is attached to a calendar, so every time a new date is
selected, the list is recreated for the new date. The code then subscribes
the event handler to the new list. Here's the cose (m_ListForSelectedDay is
a member variable):
private void calendar_DateChanged(object sender, DateRangeEventArgs e)
{
// Initialize
DateTime newDate = e.Start;
// Get daily ist for new date
m_ListForSelectedDay = GetDailyList(newDate);
// Subscribe to ListChanged event
m_ListForSelectedDay.ListChanged += new
ListChangedEventHandler(ListForSelectedDay_ListCha nged);
}
Do I need to unsubscribe from the ListChanged event before I point the
ListForSelectedDay variable to a new list? If I de-reference the object, but
I still have an event handler subscribed to it, will that keep the object
from being garbage-collected? Thanks in advance.
--
David Veeneman
Foresight Systems