Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add dispose functions and fix memory leaks #643 for 1.x #734

Merged
merged 1 commit into from
Feb 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/dash-playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,14 @@ export default class DashPlaylistLoader extends EventTarget {
}

dispose() {
this.trigger('dispose');
this.stopRequest();
this.loadedPlaylists_ = {};
window.clearTimeout(this.minimumUpdatePeriodTimeout_);
window.clearTimeout(this.mediaRequest_);
window.clearTimeout(this.mediaUpdateTimeout);

this.off();
}

hasPendingRequest() {
Expand Down
6 changes: 6 additions & 0 deletions src/master-playlist-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@ export class MasterPlaylistController extends videojs.EventTarget {
* that it controls
*/
dispose() {
this.trigger('dispose');
this.decrypter_.terminate();
this.masterPlaylistLoader_.dispose();
this.mainSegmentLoader_.dispose();
Expand All @@ -1055,6 +1056,11 @@ export class MasterPlaylistController extends videojs.EventTarget {

this.audioSegmentLoader_.dispose();
this.subtitleSegmentLoader_.dispose();
this.off();

if (this.mediaSource.dispose) {
this.mediaSource.dispose();
}
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/mse/html-media-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,4 +340,17 @@ export default class HtmlMediaSource extends videojs.EventTarget {
this.sourceBuffers.push(buffer);
return buffer;
}

dispose() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the virtual-source-buffer dispose are the only changes from master as they did not exist.

this.trigger('dispose');
this.off();

this.sourceBuffers.forEach(function(buffer) {
if (buffer.dispose) {
buffer.dispose();
}
});

this.sourceBuffers.length = 0;
}
}
5 changes: 5 additions & 0 deletions src/mse/virtual-source-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -600,4 +600,9 @@ export default class VirtualSourceBuffer extends videojs.EventTarget {
this.pendingBuffers_.length = 0;
this.bufferUpdating_ = false;
}

dispose() {
this.trigger('dispose');
this.off();
}
}
2 changes: 2 additions & 0 deletions src/playlist-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,11 @@ export default class PlaylistLoader extends EventTarget {
* Abort any outstanding work and clean up.
*/
dispose() {
this.trigger('dispose');
this.stopRequest();
window.clearTimeout(this.mediaUpdateTimeout);
window.clearTimeout(this.finalRenditionTimeout);
this.off();
}

stopRequest() {
Expand Down
14 changes: 13 additions & 1 deletion src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ export default class SegmentLoader extends videojs.EventTarget {
time: 0
};

this.syncController_.on('syncinfoupdate', () => this.trigger('syncinfoupdate'));
this.triggerSyncInfoUpdate_ = () => this.trigger('syncinfoupdate')
this.syncController_.on('syncinfoupdate', this.triggerSyncInfoUpdate_);

this.mediaSource_.addEventListener('sourceopen', () => this.ended_ = false);

Expand Down Expand Up @@ -247,6 +248,7 @@ export default class SegmentLoader extends videojs.EventTarget {
* dispose of the SegmentLoader and reset to the default state
*/
dispose() {
this.trigger('dispose');
this.state = 'DISPOSED';
this.pause();
this.abort_();
Expand All @@ -257,6 +259,16 @@ export default class SegmentLoader extends videojs.EventTarget {
if (this.captionParser_) {
this.captionParser_.reset();
}

if (this.checkBufferTimeout_) {
window.clearTimeout(this.checkBufferTimeout_);
}

if (this.syncController_ && this.triggerSyncInfoUpdate_) {
this.syncController_.off('syncinfoupdate', this.triggerSyncInfoUpdate_);
}

this.off();
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/sync-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,4 +586,9 @@ export default class SyncController extends videojs.EventTarget {
}
}
}

dispose() {
this.trigger('dispose');
this.off();
}
}