diff --git a/lib/dash/dash_parser.js b/lib/dash/dash_parser.js index 4326c3fba8..4f15675da9 100644 --- a/lib/dash/dash_parser.js +++ b/lib/dash/dash_parser.js @@ -633,6 +633,8 @@ shaka.dash.DashParser = class { } } } + // Clean the array instead of creating a new one. By doing this we ensure + // that references to the array does not change in callback functions. this.lastCalculatedBaseUris_.splice(0); if (!someLocationValid || !this.contentSteeringManager_) { const uris = uriObjs.map(TXml.getContents); @@ -641,6 +643,9 @@ shaka.dash.DashParser = class { manifestBaseUris, uris)); } + // Here we are creating local variables to avoid direct references to `this` + // in a callback function. By doing this we can ensure that garbage + // collector can clean up `this` object when it is no longer needed. const contentSteeringManager = this.contentSteeringManager_; const lastCalculatedBaseUris = this.lastCalculatedBaseUris_; @@ -648,6 +653,8 @@ shaka.dash.DashParser = class { if (contentSteeringManager && someLocationValid) { return contentSteeringManager.getLocations('BaseURL'); } + // Return the copy, because caller of this function is not an owner + // of the array. return lastCalculatedBaseUris.slice(); }; @@ -2785,6 +2792,9 @@ shaka.dash.DashParser = class { calculatedBaseUris = uriObjs.map(TXml.getContents); } + // Here we are creating local variable to avoid direct references to `this` + // in a callback function. By doing this we can ensure that garbage + // collector can clean up `this` object when it is no longer needed. const contentSteeringManager = this.contentSteeringManager_; const getFrameUris = () => {