destroy callbacks even if they aren't called, when java object is destroyed

Summary:
JSI callbacks are only destroyed if the callback is called. If the callback is never called, we're potentially leaking a lot of callbacks.

To mitigate this, we add a wrapper object that is owned by the std::function. Whenever the std::function is destroyed, the wrapper is destroyed and it deallocates the callback as well.

Changelog: [Internal]

Reviewed By: RSNara

Differential Revision: D27436402

fbshipit-source-id: d153640d5d7988c7fadaf2cb332ec00dadd0689a
This commit is contained in:
Joshua Gross
2021-04-01 16:26:47 -07:00
committed by Facebook GitHub Bot
parent 0901830977
commit 3d1afbbda3
7 changed files with 93 additions and 30 deletions
@@ -23,6 +23,13 @@ public class ReactFeatureFlags {
*/
public static volatile boolean useTurboModules = false;
/**
* Should application use the new TM callback manager in Cxx? This is assumed to be a sane
* default, but it's new. We will delete once (1) we know it's safe to ship and (2) we have
* quantified impact.
*/
public static volatile boolean useTurboModulesRAIICallbackManager = false;
/** Should we dispatch TurboModule methods with promise returns to the NativeModules thread? */
public static volatile boolean enableTurboModulePromiseAsyncDispatch = false;