Repository navigation
Feature/pipeline explicit native release #29
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
Merged
repugraf
merged 8 commits into
repugraf:main
from
MantaLabsAI:feature/pipeline-explicit-native-release
Sep 26, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fbf8b10
feat(pipeline): add dispose() for explicit native release
IrishBAM 1a634d2
refactor(pipeline): make dispose() non-blocking, drop reference only
IrishBAM 9037820
fix: enforce stop-first contract in Pipeline.dispose()
IrishBAM 8c5cb16
fix(pipeline): dispose() forces NULL then frees instead of throwing (…
IrishBAM 257a5f7
fix(test): drain bus to EOS before stop() to avoid basesrc race on Wi…
IrishBAM 305a713
refactor(pipeline): dedupe state-change methods and timeout parsing
IrishBAM ce020c6
chore: revert unrelated EOS test-stabilization changes
IrishBAM 6f07208
feat(pipeline): release native pipeline in destructor
IrishBAM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #!/usr/bin/env node | ||
| /** | ||
| * Pipeline Disposal Example | ||
| * | ||
| * Demonstrates dispose() — releasing a pipeline's native memory eagerly instead | ||
| * of waiting for garbage collection to finalize the wrapper. | ||
| * | ||
| * The native GstPipeline allocation is invisible to V8's heap accounting, so a | ||
| * pipeline you simply drop is not reclaimed until GC happens to collect the small | ||
| * JS wrapper. A process that builds a pipeline per unit of work (recording, | ||
| * transcode, feed) can see RSS climb steadily while the JS heap stays flat. | ||
| * dispose() closes that gap: it drives the pipeline to NULL if it is not already | ||
| * there and drops the native reference synchronously, so the memory is released | ||
| * without waiting for GC. Stopping first is recommended so dispose() stays cheap | ||
| * and non-blocking, but dispose() will force the NULL transition itself if | ||
| * needed. | ||
| * | ||
| * This example builds, plays, stops, and disposes many short-lived pipelines in a | ||
| * loop — the exact pattern where relying on GC timing leaks native memory. RSS is | ||
| * always reported; run with `node --expose-gc examples/dispose.mjs` to also force | ||
| * a GC at the end so the "after" figure excludes collectable JS wrappers. | ||
| */ | ||
| import { Pipeline } from "../dist/esm/index.mjs"; | ||
|
|
||
| const ITERATIONS = 25; | ||
|
|
||
| function rssMb() { | ||
| return (process.memoryUsage().rss / 1024 / 1024).toFixed(1); | ||
| } | ||
|
|
||
| console.log(`📊 RSS before: ${rssMb()} MB`); | ||
|
|
||
| for (let i = 1; i <= ITERATIONS; i++) { | ||
| const pipeline = new Pipeline("videotestsrc ! fakesink"); | ||
|
|
||
| await pipeline.play(); | ||
| await pipeline.stop(); | ||
|
|
||
| // Release the native pipeline now. Without this, each iteration's native | ||
| // allocation would linger until GC decided to collect the wrapper. | ||
| pipeline.dispose(); | ||
|
|
||
| // dispose() is idempotent and terminal: a second call is a no-op, and any | ||
| // other method call after dispose() throws "Pipeline used after dispose()". | ||
| pipeline.dispose(); | ||
| try { | ||
| pipeline.playing(); | ||
| } catch (err) { | ||
| if (i === 1) console.log(`🔒 use-after-dispose is guarded: ${err.message}`); | ||
| } | ||
|
|
||
| if (i % 5 === 0) console.log(`♻️ disposed ${i}/${ITERATIONS} — RSS: ${rssMb()} MB`); | ||
| } | ||
|
|
||
| if (typeof globalThis.gc === "function") { | ||
| globalThis.gc(); | ||
| } | ||
|
|
||
| console.log(`📊 RSS after: ${rssMb()} MB`); | ||
| console.log("✅ Done — native pipelines were released as each one finished."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.