From e6f7bca098fa50f2052b9fc80a898a8e767fec3d Mon Sep 17 00:00:00 2001 From: Moshe Zemah <35146205+MosheZemah@users.noreply.github.com> Date: Thu, 15 Aug 2019 18:30:43 +0300 Subject: [PATCH 1/4] Free resources (free detached nodes from memory) Found an issue when using virtualized list (https://github.com/bvaughn/react-virtualized), where unmounted react components (connected to store using connect) were not collected by the garbage collector. I'm not sure what is the exact explanation here, but it solved my problem. --- src/components/connectAdvanced.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/components/connectAdvanced.js b/src/components/connectAdvanced.js index ccc929a74..324ecdffc 100644 --- a/src/components/connectAdvanced.js +++ b/src/components/connectAdvanced.js @@ -368,6 +368,8 @@ export default function connectAdvanced( const unsubscribeWrapper = () => { didUnsubscribe = true subscription.tryUnsubscribe() + // free resources + subscription.onStateChange = null if (lastThrownError) { // It's possible that we caught an error due to a bad mapState function, but the From 8f8e3ce8cbd27bab388743d01a97ac6ec7c378d7 Mon Sep 17 00:00:00 2001 From: Moshe Zemah <35146205+MosheZemah@users.noreply.github.com> Date: Thu, 15 Aug 2019 18:38:30 +0300 Subject: [PATCH 2/4] Fix lint issue --- src/components/connectAdvanced.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/connectAdvanced.js b/src/components/connectAdvanced.js index 324ecdffc..5af0abfb3 100644 --- a/src/components/connectAdvanced.js +++ b/src/components/connectAdvanced.js @@ -369,8 +369,8 @@ export default function connectAdvanced( didUnsubscribe = true subscription.tryUnsubscribe() // free resources - subscription.onStateChange = null - + subscription.onStateChange = null + if (lastThrownError) { // It's possible that we caught an error due to a bad mapState function, but the // parent re-rendered without this component and we're about to unmount. From 2fa0618e7b4f84b3f3f30d52f1c406386024c824 Mon Sep 17 00:00:00 2001 From: Moshe Zemah <35146205+MosheZemah@users.noreply.github.com> Date: Thu, 15 Aug 2019 18:49:55 +0300 Subject: [PATCH 3/4] Fix lint issue --- src/components/connectAdvanced.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/connectAdvanced.js b/src/components/connectAdvanced.js index 5af0abfb3..29cb7068f 100644 --- a/src/components/connectAdvanced.js +++ b/src/components/connectAdvanced.js @@ -370,7 +370,7 @@ export default function connectAdvanced( subscription.tryUnsubscribe() // free resources subscription.onStateChange = null - + if (lastThrownError) { // It's possible that we caught an error due to a bad mapState function, but the // parent re-rendered without this component and we're about to unmount. From 8c7001eda9e9803ee4da98d9fc450490e07bd10a Mon Sep 17 00:00:00 2001 From: Moshe Zemah <35146205+MosheZemah@users.noreply.github.com> Date: Sun, 18 Aug 2019 09:00:15 +0300 Subject: [PATCH 4/4] Update src/components/connectAdvanced.js Remove comment Co-Authored-By: Tim Dorr --- src/components/connectAdvanced.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/components/connectAdvanced.js b/src/components/connectAdvanced.js index 29cb7068f..e3e6f1da4 100644 --- a/src/components/connectAdvanced.js +++ b/src/components/connectAdvanced.js @@ -368,7 +368,6 @@ export default function connectAdvanced( const unsubscribeWrapper = () => { didUnsubscribe = true subscription.tryUnsubscribe() - // free resources subscription.onStateChange = null if (lastThrownError) {