Cleaning up some memory issues.

Reuse the context in the run loop.  Not a great practice to create thousands of these if it can be reused.

Adding Dispose calls to the Context and the Image that is created.
This commit is contained in:
bholmes 2013-09-27 11:50:29 -04:00
Родитель f9bb4d642b
Коммит 93d01b3f85
1 изменённых файлов: 23 добавлений и 17 удалений

Просмотреть файл

@ -57,29 +57,35 @@ namespace coreimage
BarButton.Enabled = false;
ShouldStop = false;
foreach(var filter in FilterList)
{
Title = filter.Name;
using (var context = CIContext.FromOptions (null)) {
if (ShouldStop)
break;
foreach(var filter in FilterList)
{
Title = filter.Name;
UIImage resultImage = await Task.Factory.StartNew ( () =>{
var output = filter.Callback ();
var context = CIContext.FromOptions (null);
var result = context.CreateCGImage (output, output.Extent);
return UIImage.FromImage (result);
});
if (ShouldStop)
break;
if (ShouldStop)
break;
var resultImageTask = Task.Factory.StartNew ( () =>{
var output = filter.Callback ();
using (var result = context.CreateCGImage (output, output.Extent)) {
return UIImage.FromImage (result);
}
});
if (ImageView.Image != null)
ImageView.Image.Dispose ();
var resultImage = await resultImageTask;
ImageView.Image = resultImage;
if (ShouldStop)
break;
await PerformActionOnTestImage (resultImage, filter);
if (ImageView.Image != null)
ImageView.Image.Dispose ();
ImageView.Image = resultImage;
await PerformActionOnTestImage (resultImage, filter);
}
}
}