Subscribe on changes!

memory leak through nested reactivity

avatar
Oct 31st 2022

Vue version

3.2.41

Link to minimal reproduction

https://sfc.vuejs.org/#eNq9VE2PmzAQ/Ssjn8juBhJVeyHJqquce6l6CzkYcIITsC1/sI0i/nvHGBqS3UNPlZAYz+d7D8ZX8q5U3DpGUrK2rFE1tewtEwDrkre9gWburJUiHACMvdRsk5Fc6pLpuaYldyaFV/V7BTktzkctnSjnhaylTkGzcgWDndcYzsjY6HtR8+KMnTSjheUt21ZUHBk8b2A5Zg0QAH6ygtaF8/gGVEmANYK84QXYOq2ZsOPxekUYdyO6bmwyoYkmtPOD1AiJW6aplRq4gOVikRFIz+wyCWTk77S+vXG1/UHVbozvv5gxWutkIjUeTaG5smCYdQo9vFFSW/BdDy+oXaOcZSV0cNCygYzg58rIylcmCfyquAF8KCimEXtDRcHAMmP7SilQBzPkVvIDKkbby9CUiyOYSrq6hBxVLaTAqkCAow0bjyD6tpjhsBB8kDEkLH38ljEogcERehTNYPMGV69BzSw0ffTaYRkAYobIezn6Fit8rScY4pbWjqH3+XkWGoAv3/E9ZvdctsNvgdkR90gAeuE1qqmFT0ZfN4X4WIadsPIOYWDxrjW9YHS3v0d6CkhPiPTVvyfYbsWYo/D33o4anGaBCzwhxacHJQeaocdkeKycqaLg+Mxtkug5TiiOyv+f78D/RfWpGA+KD0VfwfwUREYBC44OY/0QT2GdhD3CDSIvJCzRHIHEJyMF3m99P1zgPmAyko4Tho1K0aisVSZNEnMo/K14MrHUxwStWDthecNiZpp5ruWHYRobh2sKmXek+wNJgsMZ

Steps to reproduce

Open the memory tab of the browser and click the "Recalculate" button a few times, see the memory rise steadily and not being reclaimed, even after a forced GC.

What is expected?

Memory usage should stay close to constant as the amount of stored data stays the same when recalculating

What is actually happening?

Memory usage continuously climbs

System Info

No response

Any additional comments?

Noticed massive slowdowns in our calculation heavy app in production after migrating to vue/nuxt3. Seems like this memory leak is the reason for that.

avatar
Nov 2nd 2022

I feel this is not strictly called a memory leak. The dynamic creation of computed causes memory to continue to grow. This is a result of improper use of computed. Let's say you create 1000 objects dynamically and they are all being used, of course, the GC can't recycle them.

avatar
Nov 2nd 2022

Also note that you need to put the computed() at the level of the script setup. By being within a method, it's not attached to the component. But this is not a memory leak because this function

const pickComputed = (i) => {
  return computed(() => {
    return computedMap.value[i];
  });
};

should not contain a computed within a function