Skip to main content
marliton
Community Expert
Community Expert
December 13, 2017
Answered

Unload a video with PreloadJS

  • December 13, 2017
  • 1 reply
  • 848 views

Hi. I have uploaded a video using the VideoLoader class of PreloadJS. Can I "unload" that video? I want to remove it and release the memory. Thanks.

var carga = new createjs.VideoLoader("new-year.mp4");

carga.load();

carga.addEventListener("complete", cargado);

var vid;

function cargado(evt) {

     vid = evt.result;

     var video = new createjs.Bitmap(vid);

     stage.addChild(video);

     vid.play();

}

This topic has been closed for replies.
Correct answer ClayUUID

The video element should be automatically garbage-collected when no variables are left that reference it. So this should wipe the slate clean:

vid = null;

video.image.src = null;

video.image = null;

video.parent.removeChild(video);

1 reply

Legend
December 13, 2017

I'm not sure how to answer your question, but putting the load() command before you've assigned your load complete event listener is just begging for trouble.

Why are you even using the Loader class? You can create a bitmap video object directly, as demonstrated here:

Re: How to put animation over video in HTML5 canvas

marliton
Community Expert
marlitonCommunity ExpertAuthor
Community Expert
December 16, 2017

Hi. Thank you for the advice about the position of the load() method.

I'm using the VideoLoader class because I need to load several videos at the same time and because I need use the listener. My problem is I can't remove the video after load, seems it exist in a "separate layer".

Marlon Ceballos
ClayUUIDCorrect answer
Legend
December 17, 2017

The video element should be automatically garbage-collected when no variables are left that reference it. So this should wipe the slate clean:

vid = null;

video.image.src = null;

video.image = null;

video.parent.removeChild(video);