Camera Windows Phone 8.1 MediaCapture捕获PhotoToStorage文件异步内存泄漏

Camera Windows Phone 8.1 MediaCapture捕获PhotoToStorage文件异步内存泄漏,camera,windows-runtime,windows-phone-8.1,universal,Camera,Windows Runtime,Windows Phone 8.1,Universal,我正在为timelapse构建一个通用应用程序,它可以在指定的时间间隔捕获一系列照片。在我的计时器滴答声事件中,我正在捕获图像并将其保存到存储文件中,如下所示: StorageFile file = await appFolder.CreateFileAsync(IMAGE_FILE_ROOT, Windows.Storage.CreationCollisionOption.GenerateUniqueName); ImageEncodingProperties imageProperties

我正在为timelapse构建一个通用应用程序,它可以在指定的时间间隔捕获一系列照片。在我的计时器滴答声事件中,我正在捕获图像并将其保存到存储文件中,如下所示:

StorageFile file = await appFolder.CreateFileAsync(IMAGE_FILE_ROOT, Windows.Storage.CreationCollisionOption.GenerateUniqueName);
ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg();
await MediaCaptureManager.CapturePhotoToStorageFileAsync(imageProperties, file);
ImageFilePaths.Add(file.Path);
file = null;
在手机上以最高分辨率(低分辨率140)成功拍摄了大约30幅图像后,我在CapturePhotoToStorageFileAsync方法中遇到内存不足的异常

我试着将照片拍摄到InMemoryRandomAccessStream,这样我就可以省去StorageFile API中的漏洞,但它仍然会泄漏

我用WinPhone Power Tools分析了内存利用率,在拍照过程中,内存利用率不断上升

我能做些什么来解决这个问题吗

更新:

以下是演示泄漏的测试代码:

for (int x = 0; x < 40; x++)
{
    using (IRandomAccessStream memoryStream = new InMemoryRandomAccessStream())
    {
        await MediaCaptureManager.CapturePhotoToStreamAsync(imageProperties, memoryStream);
    }

    await Task.Delay(1000);
}
for(int x=0;x<40;x++)
{
使用(irandomaccesstream memoryStream=new InMemoryRandomAccessStream())
{
等待MediaCaptureManager.CapturePhotoToStreamAsync(imageProperties,memoryStream);
}
等待任务。延迟(1000);
}

所以我想出了解决这个问题的办法

显然,内存泄漏与音频驱动程序有关。如果像这样初始化MediaCaptureManager,泄漏将消失

var mediaSettings = new MediaCaptureInitializationSettings
 {
  PhotoCaptureSource = PhotoCaptureSource.Auto,
  StreamingCaptureMode = StreamingCaptureMode.Video,
  AudioDeviceId = string.Empty
 };

你能分享多一点代码吗?这可能会有帮助,所以我每2秒钟在我的WinPhone应用程序中使用MediaCapture API拍摄一次照片(以便稍后使用创建timelapse视频)。代码工作正常(拍摄照片并保存),但在大约30张照片之后,应用程序的内存不足。我运行了Windows Phone Power Tools,并对应用程序进行了内存配置,在应用程序崩溃之前,它一直在消耗越来越多的内存。仅供参考,手机上有大量可用的图片存储空间。为了隔离泄漏,我分析了以下测试代码,并遇到了相同的问题:for(int x=0;x<40;x++){using(irandomaccesstream memoryStream=new inmemoryrandomaccesstream(){wait MediaCaptureManager.capturePhotostreamasync(imageProperties,memoryStream);}等待任务。延迟(1000);}此外,我尝试处理MediaCaptureManager并在拍照后重新初始化它,但泄漏仍然存在。