fix(android): Release PreviewView when the React view is dropped - #4185
Open
vgorte wants to merge 1 commit into
Open
fix(android): Release PreviewView when the React view is dropped#4185vgorte wants to merge 1 commit into
vgorte wants to merge 1 commit into
Conversation
Nitro does not call `dispose()` on unmount, so the `PreviewView` and its `SurfaceView` stayed reachable after every unmount. `onDropView()` now removes the stream-state observer, detaches the surface provider and drops the view reference. Fixes margelo#4180
|
@vgorte is attempting to deploy a commit to the Margelo Team on Vercel. A member of the Team first needs to authorize it. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #4180
Problem
HybridPreviewViewonly detached itsPreviewViewfrom the preview output when thepreviewOutputprop changed, and only removed the stream-state observer indispose(),which Nitro does not call on unmount. After every
<Camera>unmount thePreviewViewand its
SurfaceViewstayed reachable viaPreview.mSurfaceProviderand via thehybrid's own field until Hermes happened to collect the JS wrappers.
Change
onDropView()anddispose()now release the view on the UI thread: remove theobserver, remove the surface provider from the output, drop the
PreviewViewreference.Prop setters and connect/disconnect return early once the view is dropped.
Evidence
Reporter's 300 ms mount/unmount toggle, emulator API 36, heap dump after a forced Java GC
(no Hermes GC), instance counts via shark-cli:
PreviewView/SurfaceViewNote on the dump in the issue: it counts
HybridPreviewView/HybridPreviewOutputinstances, which are JS-owned and only disappear with a Hermes GC. That count is the same
with and without this change; the
SurfaceViewcount above is the one that was leaking.Test
visioncamera.nativepreviewview.harness.tsx: re-uses one preview output across an oldand a replacement
NativePreviewViewin a single update. Native retention is notobservable from JS, so this guards the interaction the change touches rather than the
leak itself. Heap dumps available on request.