From ed835752bc9f632e91c747565a88e07c9b2d6179 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 26 May 2016 13:51:51 +0100 Subject: [PATCH 1/3] Hopefully fix memory leak with velocity --- src/Velociraptor.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Velociraptor.js b/src/Velociraptor.js index ad12d1323b..bad921c8c4 100644 --- a/src/Velociraptor.js +++ b/src/Velociraptor.js @@ -25,6 +25,10 @@ module.exports = React.createClass({ this._updateChildren(this.props.children); }, + componentWillUnmount: function() { + this._updateChildren([]); + }, + componentWillReceiveProps: function(nextProps) { this._updateChildren(nextProps.children); }, @@ -106,6 +110,9 @@ module.exports = React.createClass({ }); //console.log("enter: "+JSON.stringify(node.props._restingStyle)); + } else if (node === null) { + // https://github.com/julianshapiro/velocity/issues/300 + Velocity.Utilities.removeData(this.nodes[k]); } this.nodes[k] = node; }, From 3a5e37aa84cf16df1db1d2b0be917a6745ed0584 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 26 May 2016 16:22:40 +0100 Subject: [PATCH 2/3] This actually shouldn't be necessary. --- src/Velociraptor.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Velociraptor.js b/src/Velociraptor.js index bad921c8c4..9132f7b7b9 100644 --- a/src/Velociraptor.js +++ b/src/Velociraptor.js @@ -25,10 +25,6 @@ module.exports = React.createClass({ this._updateChildren(this.props.children); }, - componentWillUnmount: function() { - this._updateChildren([]); - }, - componentWillReceiveProps: function(nextProps) { this._updateChildren(nextProps.children); }, From 1664f461805c7b8ac772a7b67c1f9f5faa52dd4d Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 26 May 2016 16:30:04 +0100 Subject: [PATCH 3/3] Add comment --- src/Velociraptor.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Velociraptor.js b/src/Velociraptor.js index 9132f7b7b9..0abf34b230 100644 --- a/src/Velociraptor.js +++ b/src/Velociraptor.js @@ -107,7 +107,16 @@ module.exports = React.createClass({ //console.log("enter: "+JSON.stringify(node.props._restingStyle)); } else if (node === null) { + // Velocity stores data on elements using the jQuery .data() + // method, and assumes you'll be using jQuery's .remove() to + // remove the element, but we don't use jQuery, so we need to + // blow away the element's data explicitly otherwise it will leak. + // This uses Velocity's internal jQuery compatible wrapper. + // See the bug at // https://github.com/julianshapiro/velocity/issues/300 + // and the FAQ entry, "Preventing memory leaks when + // creating/destroying large numbers of elements" + // (https://github.com/julianshapiro/velocity/issues/47) Velocity.Utilities.removeData(this.nodes[k]); } this.nodes[k] = node;