Question

Does removing an html5 media DOM element (video or audio) also free any memory used by the media represented by that element? (assuming no references in code also)

Was it helpful?

Solution

From the specification:

4.8.10.16 Best practices for authors using media elements

Playing audio and video resources on small devices such as set-top boxes or mobile phones is often constrained by limited hardware resources in the device. For example, a device might only support three simultaneous videos. For this reason, it is a good practice to release resources held by media elements when they are done playing, either by being very careful about removing all references to the element and allowing it to be garbage collected, or, even better, by removing the element's src attribute and any source element descendants, and invoking the element's load() method.

Similarly, when the playback rate is not exactly 1.0, hardware, software, or format limitations can cause video frames to be dropped and audio to be choppy or muted.

source: http://dev.w3.org/html5/spec-author-view/video.html#media-resource

OTHER TIPS

An object is garbage collected when there is no more reference to it.
If you remove the element from DOM, it is cleared from memory, if there is no variable pointing to it.

In this example, there is variable "img" that still holds the object. So when we remove it from DOM it is not cleared from memory.

img.parentNode.removeChild(img);

We are able to append it to DOM again.

document.body.appendChild(img);

http://jsfiddle.net/rgH2A/

The above-mentioned concerned MEMORY. Whether to clear files from CACHE or not is up to the browser to decide in any case.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top