Skip to content

Commit

Permalink
Fix memory leak in MessageQueue
Browse files Browse the repository at this point in the history
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 #9611

Differential Revision: D3781875

fbshipit-source-id: 58c645c52c3e295fe571b7ca7e0d882169c301ef
  • Loading branch information
Adam Comella authored and Facebook Github Bot 5 committed Aug 27, 2016
1 parent e6de198 commit 5d748b2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Libraries/Utilities/MessageQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 5d748b2

Please sign in to comment.