Skip to content

Commit

Permalink
Immediately destroy EventEmitterWrapper on update instead of waiting …
Browse files Browse the repository at this point in the history
…for GC

Summary:
Immediately destroy EventEmitterWrapper on update instead of waiting for Java GC. This can resolve JSI::~Pointer deallocation crashes by clearing out EventEmitter and therefore EventTarget sooner, before RN teardown.

Changelog: [Internal]

Reviewed By: fkgozali

Differential Revision: D29415386

fbshipit-source-id: 05517bfd9e2cc2bd1b8c58d4f84c84f6f547268a
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Jun 26, 2021
1 parent afafbf8 commit 41eccce
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,13 @@ public void updateEventEmitter(int reactTag, @NonNull EventEmitterWrapper eventE
viewState = new ViewState(reactTag, null, null);
mTagToViewState.put(reactTag, viewState);
}
EventEmitterWrapper previousEventEmitterWrapper = viewState.mEventEmitter;
viewState.mEventEmitter = eventEmitter;

// Immediately destroy native side of wrapper, instead of waiting for Java GC.
if (previousEventEmitterWrapper != eventEmitter && previousEventEmitterWrapper != null) {
previousEventEmitterWrapper.destroy();
}
}

@UiThread
Expand Down

0 comments on commit 41eccce

Please sign in to comment.