私は、USBドライブからビデオファイルを読み込んで、物理的なボタンを使ってビデオファイルを切り替えることのできるアプリケーションを構築しました。アプリケーションはしばらくはうまくいくが、しばらくすると、すべてのメモリがアプリケーションによって消費されたため、デバイス(DragonBoard 410c、最新のWindows Insider Preview Build 15051)がクラッシュする。Windows IoTでメモリリークを再生する| UWP
デバイスポータルのプロセスを見ると、ビデオファイルを切り替えるたびに「ワーキングセット」メモリがジャンプするのがわかります。「プライベートワーキングセット」はほぼ同じままです(約30MB)。私はいくつかの場所で手動)(GC.Collectを実行しようとしたませんが、まだ運き
C#
private IReadOnlyList<StorageFile> _videofiles
// list all available video files
public void Init(){
var queryOptions = new QueryOptions();
queryOptions.FolderDepth = depth;
foreach (var fileType in fileTypes)
{
queryOptions.FileTypeFilter.Add(fileType);
}
var query = KnownFolders.RemovableDevices.CreateFileQueryWithOptions(queryOptions);
_videofiles = await query.GetFilesAsync();
}
private async void SelectVideo(int videoId)
{
StorageFile videofile = _videofiles.Where(x => x.DisplayName == videoId.ToString()).FirstOrDefault();
if (videofile != null)
{
Debug.WriteLine($"Video {videofile.DisplayName} was selected");
var stream = await videofile.OpenAsync(FileAccessMode.Read);
VideoPlayer.SetSource(stream, videofile.FileType);
}
}
// since the button interrupt is not on the UI thread, SelectVideo() is called like this
private async void SelectVideoMarshalled(int videoId)
{
await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
SelectVideo(videoId);
});
}
XAML
<ContentControl x:Name="VideoPlayer" Content="{x:Bind ViewModel.VideoPlayer, Mode=OneWay}"/>
:ここ
は、私はビデオファイルをロードする方法を説明します。何か案は?
すべてのストリームは使い捨てですので、 'SelectVideo'メソッドでストリームの新しいインスタンスに設定した後、' VideoPlayer'のソースとして設定した前のストリームを破棄する必要があります。 –
ストリームの呼び出し.Dispose(); VideoPlayer.SetSource()の直後(これはメモリのスパイクが発生する場所です)は役に立ちません。 – Thomas
別のページに移動してもメモリを解放するのに役立たない – Thomas