Skip to content

Commit d69d2a7

Browse files
tykus160avelad
authored andcommitted
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 1a7054d commit d69d2a7

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
@@ -617,21 +617,22 @@ shaka.dash.DashParser = class {
617617
}
618618
}
619619
}
620-
this.lastCalculatedBaseUris_ = null;
620+
this.lastCalculatedBaseUris_.splice(0);
621621
if (!someLocationValid || !this.contentSteeringManager_) {
622622
const uris = uriObjs.map(TXml.getContents);
623-
this.lastCalculatedBaseUris_ = shaka.util.ManifestParserUtils.resolveUris(
624-
manifestBaseUris, uris);
623+
this.lastCalculatedBaseUris_.push(
624+
...shaka.util.ManifestParserUtils.resolveUris(
625+
manifestBaseUris, uris));
625626
}
626627

628+
const contentSteeringManager = this.contentSteeringManager_;
629+
const lastCalculatedBaseUris = this.lastCalculatedBaseUris_;
630+
627631
const getBaseUris = () => {
628-
if (this.contentSteeringManager_ && someLocationValid) {
629-
return this.contentSteeringManager_.getLocations('BaseURL');
630-
}
631-
if (this.lastCalculatedBaseUris_) {
632-
return this.lastCalculatedBaseUris_;
632+
if (contentSteeringManager && someLocationValid) {
633+
return contentSteeringManager.getLocations('BaseURL');
633634
}
634-
return [];
635+
return lastCalculatedBaseUris.slice();
635636
};
636637

637638
this.manifestPatchContext_.getBaseUris = getBaseUris;
@@ -2666,12 +2667,14 @@ shaka.dash.DashParser = class {
26662667
calculatedBaseUris = uriObjs.map(TXml.getContents);
26672668
}
26682669

2670+
const contentSteeringManager = this.contentSteeringManager_;
2671+
26692672
const getFrameUris = () => {
26702673
if (!uriObjs.length) {
26712674
return [];
26722675
}
2673-
if (this.contentSteeringManager_ && someLocationValid) {
2674-
return this.contentSteeringManager_.getLocations(id);
2676+
if (contentSteeringManager && someLocationValid) {
2677+
return contentSteeringManager.getLocations(id);
26752678
}
26762679
if (calculatedBaseUris) {
26772680
return calculatedBaseUris;

0 commit comments

Comments
 (0)