Fix memory leak in MessageQueue

Summary:
The MessageQueue has a _debugInfo object where it stores debug information associated with each callback. The size of this structure is currently unbounded.

It looks like the code attempted to restrict _debugInfo to a fixed number of entries but due to a logic bug, it leaked around 30 entries for every 1 entry it cleaned up.

This change limits the _debugInfo object to around 30 entries.

**Test plan (required)**

This change is currently being used in my team's app.

Adam Comella
Microsoft Corp.
Closes https://github.com/facebook/react-native/pull/9611

Differential Revision: D3781875

fbshipit-source-id: 58c645c52c3e295fe571b7ca7e0d882169c301ef
This commit is contained in:
Adam Comella 2016-08-26 18:44:07 -07:00 committed by Facebook Github Bot 5
parent e6de198a4b
commit 5d748b2eec
1 changed files with 7 additions and 4 deletions

View File

@ -31,6 +31,8 @@ const TO_JS = 0;
const TRACE_TAG_REACT_APPS = 1 << 17;
const DEBUG_INFO_LIMIT = 32;
const MethodTypes = keyMirror({
remote: null,
remoteAsync: null,
@ -168,10 +170,11 @@ class MessageQueue {
__nativeCall(module, method, params, onFail, onSucc) {
if (onFail || onSucc) {
if (__DEV__) {
// eventually delete old debug info
(this._callbackID > (1 << 5)) &&
(this._debugInfo[this._callbackID >> 5] = null);
this._debugInfo[this._callbackID >> 1] = [module, method];
let callId = this._callbackID >> 1;
this._debugInfo[callId] = [module, method];
if (callId > DEBUG_INFO_LIMIT) {
delete this._debugInfo[callId - DEBUG_INFO_LIMIT];
}
}
onFail && params.push(this._callbackID);
this._callbacks[this._callbackID++] = onFail;