private void CleanupImageSource()
{
try
{
ReifiedAlbumItemConverter.CancelSource.Cancel();
ReifiedAlbumItemConverter.CancelSource = new CancellationTokenSource();
this.State.Clear();
foreach (var item in albumPivot.Items)
{
if (item is PivotItem)
{
var content = ((PivotItem)item).Content;
if (content is ScalingGifView)
{
((ScalingGifView)content).ImageSource = null;
}
else if (content is ScalingPictureView)
{
((ScalingPictureView)content).ImageSource = null;
}
((PivotItem)item).Content = null;
var context = ((PivotItem)item).DataContext as BaconographyPortable.ViewModel.LinkedPictureViewModel.LinkedPicture;
context.ImageSource = null;
}
else if (item is BaconographyPortable.ViewModel.LinkedPictureViewModel.LinkedPicture)
{
((BaconographyPortable.ViewModel.LinkedPictureViewModel.LinkedPicture)item).ImageSource = null;
}
}
((LinkedPictureViewModel)DataContext).Cleanup();
if (albumPivot.ItemsSource is ObservableCollection<PivotItem>)
{
((ObservableCollection<PivotItem>)albumPivot.ItemsSource).Clear();
}
this.Content = null;
if (_gcCount <= 0)
Task.Factory.StartNew(RunGC, TaskCreationOptions.LongRunning);
}
catch
{
}
}