1
votes

How are controls created by XAML code disposed in WinRT? I have created ImageSlideShow UserControl which uses SempahoreSlim and DispatcherTimer ( i use timer.Tick event). Should I add .Unloaded event handler to ImageSlideShow user control or implement IDisposable (does xaml takes care of calling .Dispose?) to release resources and events handlers - or do I need to dispose it manually like controls created in code-behind?

1

1 Answers

4
votes

You should use Unloaded event of UserControl. In that unhook all the events, nullify the <Image /> & set ItemsSource to null if any collection control you are using.

How to nullify image?

BitmapImage bitmapImage = image.Source as BitmapImage;
bitmapImage.UriSource = null;
image.Source = null;

Here image is object of <Image />

Also implement IDisposable interface. Then you need to browse the complete UI element tree, search for your <Image /> and call Dispose on all of them.

For more info check out this (It's applicable to W8 also): How to debug most common memory leaks on WP8