[UWP] [C#] MediaPlaybackList内存泄漏 [英] [UWP][C#] MediaPlaybackList memory leak

查看:67
本文介绍了[UWP] [C#] MediaPlaybackList内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,

前一段时间我有这个奇怪的问题,经过一段时间后我的后台任务就会因为没有足够的内存继续而退出。

我想我现在发现了这个问题。



先来一点点细节:

我正在使用一个实现的自定义类IRandomAccessStreamReference接口。

使用这个类我创建MediaSources然后我将其包装在MediaPlaybackItem中并添加到MediaPlaybackList。

当调用OpenReadAsync()时,我调用异步任务实际打开文件和流并返回它的方法。

我施放了任务<>使用AsAsyncOperation()进行AsyncOperation并返回它。



所以现在问题出现了:

当浏览播放列表时(出于速度原因,我只是一直移动到下一个并且没有等待每个音轨结束)我注意到内存使用量不断上升。

每个音轨只有1-4 MB但是这一切都加起来直到达到内存限制。我可以设置一个更高的限制(尝试直到100 MB,在1 GB内存的lumia 650上仍然成功)但这显然不是一个可行的解决方案。



我解决了一个小问题:

在CurrentItemChanged处理程序中,我只需重置OldItem的MediaSource Source(如果它不为null)。

这样内存保持相对常数+/- 2MB



所以我想知道我做错了什么(并且让MediaPlaybackList无法自行释放内存)或者是否存在MediaPlaybackList中的错误?

a while ago I had this weird issue that after some time my background task would just quit because he had insufficient memory to continue.
I think I found the issue now.

First a little bit of detail:
I am using a custom class that implements the IRandomAccessStreamReference interface.
Using this class I create MediaSources which I then wrap in a MediaPlaybackItem and add to a MediaPlaybackList.
When OpenReadAsync() is called I call an async Task method that actually opens the file and the stream and returns it.
I cast the Task<> to AsyncOperation with AsAsyncOperation() and return it.

So now here's the problem:
When going through the playlist (for speed reasons i just moved to the next one all the time and didn't wait for each track to end) I noticed that the memory usage is constantly rising.
Just 1-4 MB per track but it all adds up until the memory limit is reached. I can set a higher limit (did try until 100 MB which was still successful on a lumia 650 with 1 GB RAM) but that's obviously not a viable solution.

I worked out a little workaround:
In the CurrentItemChanged handler I simply Reset the MediaSource Source of the OldItem (if it isn't null).
That way the memory remains relatively constant +/- 2MB

So I'm wondering did I do something wrong (and made it impossible for the MediaPlaybackList to free the memory by itself) or is there a bug in the MediaPlaybackList?

推荐答案

Hello St3f4n,

Hello St3f4n,

要知道这是否是一个已知问题,我们需要重现您的问题。你介意发一个简单的重复样本吗?

To know whether this is a known issue we need to reproduce your problem. Would you mind to send a simple repro sample?

请确保你已经取消了一些可能的资源,如下所述:

And please make sure you've canceled some possible resource like described here:

https://blogs.windows.com/buildingapps/2016/01/13/ the-baseics-of-background-audio /

请参阅此处的取消​​回拨。

See Cancellation Callback here.

祝你好运,

Barry


这篇关于[UWP] [C#] MediaPlaybackList内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆