Skip to content

fix: Release the Frame Output thread on dispose and unmount - #4227

Open
chocky335 wants to merge 1 commit into
margelo:mainfrom
chocky335:android/frame-output-executor-leak
Open

chocky335 wants to merge 1 commit into
margelo:mainfrom
chocky335:android/frame-output-executor-leak

Conversation

@chocky335

Copy link
Copy Markdown

What

On Android, each frame output keeps its com.margelo.camera.frame thread after the camera closes, so every camera mount leaks one thread.

How

HybridFrameOutput and HybridDepthFrameOutput now shut their executor down in dispose(). useFrameOutput disposes its output on unmount or replacement, one microtask late so a StrictMode effect re-run keeps it alive.

Review focus: the hook disposes the output while <Camera> may still have it configured until its teardown configure([]) runs.

The thread test comes from #4212 by @dmandrade. It stays red on iOS until HybridNativeThread.swift rejects work after dispose. I can follow up with that, and with the same unmount dispose in useDepthOutput.

Closes #4213

Related Pull Requests

@chocky335

Copy link
Copy Markdown
Author

Thread count on a Pixel 8 Pro, from adb shell ps -T -p <pid> sampled about every 2 s, over 10 mount and unmount cycles of <Camera outputs={[useFrameOutput(...)]}> and then a 25 s hold.

Build During the cycles After 10 cycles
Before rises from 1 to 10 10 (16 samples)
After 0 or 1 0 (17 samples)

Harness runs on the same device: both new tests fail on the baseline APK and pass with the fix (hooks and frame suites, 19 passed, 3 skipped). The two camera-view failures (initial zoom, initial torch) fail on the baseline too.

@vercel

vercel Bot commented Oct 19, 2026

Copy link
Copy Markdown

@chocky335 is attempting to deploy a commit to the Margelo Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

馃悰 [Android] Each FrameOutput leaks its native thread (dispose() doesn't shut down the executor; useFrameOutput never disposes)

1 participant