我正在开发一个实时媒体浏览/播放应用程序,在浏览器中使用<video>个对象进行播放(如果可用).

我混合使用了纯javascript和jQuery,

My concern is specifically with memory. The application never reloads in the window, and the user can watch many videos, so memory management becomes a large concern over time. In testing today, I see the memory profile jumping by the size of the video to be streamed with each subsequent load, and never dropping back down to the baseline.

I've tried the following things with the same result:

1-清空包含创建的元素的父容器,例如:

$(container_selector).empty();

2-暂停并删除与"视频"匹配的子项,然后清空父容器:

$(container_selector).children().filter("video").each(function(){
    this.pause();
    $(this).remove();
});
$(container_selector).empty();

Has anyone else run into this issue, and is there a better way to do this?

推荐答案

从DOM struct 中处理视频非常棘手.这可能会导致浏览器崩溃.这是在我的项目中帮助我的解决方案.

var videoElement = document.getElementById('id_of_the_video_element_here');
videoElement.pause();
videoElement.removeAttribute('src'); // empty source
videoElement.load();

this will reset everything, silent without errors !

Edit: Here are the full details as recommended in the Standard: https://html.spec.whatwg.org/multipage/media.html#best-practices-for-authors-using-media-elements

希望它能解决你的疑问.

Jquery相关问答推荐

如果文本框内容在 X 秒内没有更改,则进行 post 调用

如何使 jQuery.ready 中定义的函数在全局可用?

jQuery中的多个 Select 器链接?

如何在 jQuery 中使用:not 和 hasClass() 来获取没有类的特定元素

在 jQuery 中构建 html 元素的最清晰方法

jQuery.parseJSON 单引号与双引号

页面滚动后,jQuery可拖动在错误的位置显示助手

如何使用 jquery 正确格式化货币?

如何同时使用 requireJS 和 jQuery?

如何判断元素是否在屏幕外

自动完成将值而不是标签应用于文本框

jQuery:如何从 $.ajax.error 方法中获取 HTTP 状态代码?

你如何在Javascript中缓存图像

jquery: $(window).scrollTop() 但没有 $(window).scrollBottom()

如何使用 javascript (jquery) 将整数值添加到返回字符串的值中?

如何删除/更改 JQuery UI 自动完成助手文本?

jQuery从字符串中删除'-'字符

如何复制 pinterest.com 的绝对 div 堆叠布局

获取对象属性中的最小值/最大值的快速方法

jQuery中的wait()或sleep()函数?