If there are events that are on the chart, but I call dispose on the chart, does the chart actually get garbage collected or do I need to remove the event handler?
Same if I have event handlers on items such as bands; do I need to remove the event handlers for them as well?
Memory Cleanup Question
Moderator: Queue Moderators
Re: Memory Cleanup Question
Calling Dispose method doesn't mean automatic memory deallocation of an object. It just tells the object to clean up itself (i.e. release internal resources etc.) so that it is ready for garbage collection. If you want to force a garbage collection you have to call GC.Collect and GC.WaitForPendingFinalizers methods. Forcing is not recommended in most cases because GC knows what it's doing and forcing will only interrupt the current work.
What comes to events, event delegate contains reference only to event target (e.g. your main application where your event handling method is) so event source (chart, band, ...) is not affected by the event. Therefore, you don't have to unsubscribe from the events to make you chart ready for garbage collection. Just call Dispose and make sure that nothing is referencing to chart or its properties.
Events cause memory leaks if event source outlives event target. Then you have to explicitly unsubscribe from events hence making reference from event delegate to event target null. Otherwise event target won't get collected.
What comes to events, event delegate contains reference only to event target (e.g. your main application where your event handling method is) so event source (chart, band, ...) is not affected by the event. Therefore, you don't have to unsubscribe from the events to make you chart ready for garbage collection. Just call Dispose and make sure that nothing is referencing to chart or its properties.
Events cause memory leaks if event source outlives event target. Then you have to explicitly unsubscribe from events hence making reference from event delegate to event target null. Otherwise event target won't get collected.
- blakeadkins
- Posts: 44
- Joined: Tue Feb 25, 2014 7:49 pm
Re: Memory Cleanup Question
Thank you; that clears it up!