Fix FinalizationRegistry being able to prevent Inputs from being GCd in some cases (fixes #367)

This commit is contained in:
Vanilagy
2026-05-24 14:45:13 +02:00
parent 41a331b0dc
commit ef27d73405
2 changed files with 56 additions and 25 deletions
-14
View File
@@ -45,17 +45,6 @@ polyfillSymbolDispose();
export const DEFAULT_SOURCE_CACHE_GROUP = 1;
export const ENCRYPTION_KEY_CACHE_GROUP = 2;
let inputFinalizationRegistry: FinalizationRegistry<SourceRef[]> | null = null;
if (typeof FinalizationRegistry !== 'undefined') {
inputFinalizationRegistry = new FinalizationRegistry((refs) => {
for (const ref of refs) {
if (!ref.freed) {
ref.free();
}
}
});
}
/**
* The options for creating an Input object.
* @group Input files & tracks
@@ -191,7 +180,6 @@ export class Input<S extends Source = Source> extends EventEmitter<InputEvents>
}
this._sourceRefs.push(this._rootRef);
inputFinalizationRegistry?.register(this, this._sourceRefs, this);
}
/** @internal */
@@ -539,8 +527,6 @@ export class Input<S extends Source = Source> extends EventEmitter<InputEvents>
}
this._sourceRefs.length = 0;
inputFinalizationRegistry?.unregister(this);
void this._demuxerPromise
?.then(demuxer => demuxer.dispose());
}