Skip to content

Commit 27163ff

Browse files
authored
fix(DASH): Prevent memory leak in uncompiled mode (#8884)
Keeping `this` references in DASH uri callbacks leads to keeping DashParser instances in memory after unloading. Luckily this is only the issue in uncompiled mode, Closure Compiler handles it somehow. It is though better to fix it in case we change tooling some day.
1 parent 5fbf94f commit 27163ff

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/dash/dash_parser.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -633,21 +633,22 @@ shaka.dash.DashParser = class {
633633
}
634634
}
635635
}
636-
this.lastCalculatedBaseUris_ = null;
636+
this.lastCalculatedBaseUris_.splice(0);
637637
if (!someLocationValid || !this.contentSteeringManager_) {
638638
const uris = uriObjs.map(TXml.getContents);
639-
this.lastCalculatedBaseUris_ = shaka.util.ManifestParserUtils.resolveUris(
640-
manifestBaseUris, uris);
639+
this.lastCalculatedBaseUris_.push(
640+
...shaka.util.ManifestParserUtils.resolveUris(
641+
manifestBaseUris, uris));
641642
}
642643

644+
const contentSteeringManager = this.contentSteeringManager_;
645+
const lastCalculatedBaseUris = this.lastCalculatedBaseUris_;
646+
643647
const getBaseUris = () => {
644-
if (this.contentSteeringManager_ && someLocationValid) {
645-
return this.contentSteeringManager_.getLocations('BaseURL');
646-
}
647-
if (this.lastCalculatedBaseUris_) {
648-
return this.lastCalculatedBaseUris_;
648+
if (contentSteeringManager && someLocationValid) {
649+
return contentSteeringManager.getLocations('BaseURL');
649650
}
650-
return [];
651+
return lastCalculatedBaseUris.slice();
651652
};
652653

653654
this.manifestPatchContext_.getBaseUris = getBaseUris;
@@ -2784,12 +2785,14 @@ shaka.dash.DashParser = class {
27842785
calculatedBaseUris = uriObjs.map(TXml.getContents);
27852786
}
27862787

2788+
const contentSteeringManager = this.contentSteeringManager_;
2789+
27872790
const getFrameUris = () => {
27882791
if (!uriObjs.length) {
27892792
return [];
27902793
}
2791-
if (this.contentSteeringManager_ && someLocationValid) {
2792-
return this.contentSteeringManager_.getLocations(id);
2794+
if (contentSteeringManager && someLocationValid) {
2795+
return contentSteeringManager.getLocations(id);
27932796
}
27942797
if (calculatedBaseUris) {
27952798
return calculatedBaseUris;

0 commit comments

Comments
 (0)