Skip to content

Commit

Permalink
fix(core): change callbacks to object to fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
zoomchan-cxj committed Apr 18, 2022
1 parent d44d880 commit 9ea52da
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
8 changes: 3 additions & 5 deletions core/js/bridge/ios/native2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ __fbBatchedBridge.invokeCallbackAndReturnFlushedQueue = (cbID, args) => {

__fbBatchedBridge.__invokeCallback = (cbID, args) => {
const callback = __GLOBAL__._callbacks[cbID];
if (!callback) {
return;
}
if (!callback) return;

if (!__GLOBAL__._notDeleteCallbackIds[cbID & ~1]
&& !__GLOBAL__._notDeleteCallbackIds[cbID | 1]) {
__GLOBAL__._callbacks[cbID & ~1] = null;
__GLOBAL__._callbacks[cbID | 1] = null;
delete __GLOBAL__._callbacks[cbID & ~1];
delete __GLOBAL__._callbacks[cbID | 1];
}

if (args && args.length > 1 && (args[0] === null || args[0] === undefined)) {
Expand Down
3 changes: 1 addition & 2 deletions core/js/global/ios/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ __GLOBAL__.requestAnimationFrameQueue = {};
__GLOBAL__.destroyInstanceList = {};
__GLOBAL__._callID = 0;
__GLOBAL__._callbackID = 0;
__GLOBAL__._callbacks = [];
__GLOBAL__._callbacks = {};
__GLOBAL__._notDeleteCallbackIds = {};
__GLOBAL__._queue = [[], [], [], __GLOBAL__._callID];

Expand Down Expand Up @@ -58,7 +58,6 @@ __GLOBAL__.enqueueNativeCall = (moduleID, methodID, params, onFail, onSucc) => {
if (onFail || onSucc) {
if (typeof params === 'object' && params.length > 0 && typeof params[0] === 'object' && params[0].notDelete) {
params.shift();

__GLOBAL__._notDeleteCallbackIds[__GLOBAL__._callbackID] = true;
}

Expand Down
Loading

0 comments on commit 9ea52da

Please sign in to comment.