mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
f7d006e60c
Summary: changelog: [internal] ### When does leak happen? Leak happens anytime a callback isn't executed inside native module, it will never get cleaned up. Imagine a native module with method that takes onSuccess and onFail callbacks. Only one of them will be called at any time and the other one will leak. ### Why does it leak? It leaks because when `CallbackWrapper` is created using `CallbackWrapper::createWeak`. Inside `CallbackWrapper::createWeak`, the newly created object is inserted into `LongLivedObjectCollection`. This object collection will keep it alive until `CallbackWrapper::destroy` is called, which isn't called in case closure isn't executed. ### Solution Introduce class RCTBlockGuard which ties cleanup of resources to lifetime of the block. Reviewed By: RSNara Differential Revision: D26664173 fbshipit-source-id: 9348f7c39eb317cf1e8e5d59e77a378e5e04f3eb