Skip to content

Memory leak in ReactDOMInput on server rendering #4870

@STRML

Description

@STRML

In React 0.14.0-rc1 I've seen a massive memory leak as it appears my entire app is being retained.

After some time in the profiler, I narrowed it down to ReactDOMInput's instancesByReactID (I have a radio input in my app):

screen shot 2015-09-14 at 1 41 02 pm

Removing instancesByReactID entirely in the source fixes the leak.

To diagnose this, I added some log statements:

  mountWrapper: function (inst, props) {
    LinkedValueUtils.checkPropTypes('input', props, inst._currentElement._owner);

    var defaultValue = props.defaultValue;
    inst._wrapperState = {
      initialChecked: props.defaultChecked || false,
      initialValue: defaultValue != null ? defaultValue : null,
      onChange: _handleChange.bind(inst)
    };

    console.log("mounted input, id", inst._rootNodeID);
    instancesByReactID[inst._rootNodeID] = inst;
  },

  unmountWrapper: function (inst) {
    console.log("unmounted input, id", inst._rootNodeID);
    delete instancesByReactID[inst._rootNodeID];
  },

Then ran the app:

mounted input, id .gkkc0jr400.1.0.1.2.0.1.0.5.$basic/=1$basic.$basic
mounted input, id .gkkc0jr400.1.0.1.2.0.1.0.5.$basic/=1$advanced.$advanced
INFO: 127.0.0.1 (Chrome 46, Mac OS) - "GET /app/trade/XBTU15" 200 -b - 312.409 ms
mounted input, id .280er686xog.1.0.1.2.0.1.0.5.$basic/=1$basic.$basic
mounted input, id .280er686xog.1.0.1.2.0.1.0.5.$basic/=1$advanced.$advanced
INFO: 127.0.0.1 (Chrome 46, Mac OS) - "GET /app/trade/XBTU15" 200 -b - 587.734 ms

Notice that the unmount never logs, so these instances stay in instancesByReactID forever.

I am simply rendering using ReactDOMServer.renderToString().

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions