Permalink
Browse files

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 #9611

Differential Revision: D3781875

fbshipit-source-id: 58c645c52c3e295fe571b7ca7e0d882169c301ef
  • Loading branch information...
1 parent e6de198 commit 5d748b2eec0b5bb2dea4eced79aba2fd994eb20a @rigdern rigdern committed with Facebook Github Bot 5 Aug 27, 2016
Showing with 7 additions and 4 deletions.
  1. +7 −4 Libraries/Utilities/MessageQueue.js
@@ -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;

0 comments on commit 5d748b2

Please sign in to comment.