Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elements used for the initial rendering of a v-for are immune to GC #10050

Closed
peter-gy opened this issue Jan 9, 2024 · 10 comments
Closed

Elements used for the initial rendering of a v-for are immune to GC #10050

peter-gy opened this issue Jan 9, 2024 · 10 comments
Labels
need more info Further information is requested

Comments

@peter-gy
Copy link

peter-gy commented Jan 9, 2024

Vue version

3.4.6

Link to minimal reproduction

https://github.com/peter-gy/vue3-v-for-memory-leak-repro

Steps to reproduce

Using MS Edge makes it easier to investigate the detached elements, so it is recommended to use it for reproduction.
Learn more about how to use the Edge DevTools to investigate memory leaks here.

  1. Open the app in MS Edge
  2. Open the DevTools and navigate to the "Detached Elements" tab
  3. Refresh the element state and force an initial garbage collection by clicking the trash icon
  4. Set the counter to 0
  5. Refresh the element state and force a garbage collection by clicking the trash icon again
  6. See that the detached elements are still there

What is expected?

After the initial items are removed from the DOM, they are removed from memory too, they don't keep on lingering in memory as detached elements.

What is actually happening?

All of the nodes used to initially render the list remain in the memory as detached elements.

System Info

No response

Any additional comments?

Vue SFC Playground Repro Link

Screencast:

Important

While on the right side in the screencast, you can read Vue ^3.3.11, the bug is present on the current latest version 3.4.6 too. The SFC Playground links to a repro using 3.4.6.

vue3-v-for-memory-leak.mp4

The https://github.com/peter-gy/vue3-v-for-memory-leak-repro repository allows you to check side-by-side that this behavior was not present in Vue2. Our team noticed massive memory leaks in our e2e test suite as we have been working on migrating from Vue2 to Vue3.

peter-gy added a commit to peter-gy/vue3-v-for-memory-leak-repro that referenced this issue Jan 9, 2024
@edison1105
Copy link
Member

duplicate of #5256

@boutils
Copy link

boutils commented Jan 9, 2024

I think you closed this issue too quickly, I can reproduce these detached nodes even when hoistStatic is set to false.

@LinusBorg LinusBorg reopened this Jan 9, 2024
@yyx990803 yyx990803 changed the title Elements used for the initial rendering of a v-for are immune to GC and cause a memory leak Elements used for the initial rendering of a v-for are immune to GC Jan 9, 2024
@yyx990803
Copy link
Member

Do note the detached elements do not increase over time so it is not a memory leak (which implies the memory would keep growing indefinitely).

@boutils
Copy link

boutils commented Jan 9, 2024

I tend to disagree @yyx990803. In my "large" application, the v-for iterates on some dynamic user input elements. Because of these detached elements, the memory increases and increases indefinitely.

@peter-gy
Copy link
Author

peter-gy commented Jan 9, 2024

Do note the detached elements do not increase over time so it is not a memory leak (which implies the memory would keep growing indefinitely).

In our case this is exactly what we experience. We have an E2E test suite where thousands of scenarios are executed one after the other. The memory occupied by the non-garbage-collected elements keep accumulating, as we move between scenarios. This is caused by the fact that the whole test suite is executed without any browser reload. This leads to crashing the testing process with an out-of-memory error.

@yyx990803
Copy link
Member

yyx990803 commented Jan 9, 2024

Then unfortunately, your demo isn't showing the actual culprit because the detached elements you see are retained by __vnode properties which are only attached in development mode for devtools usage. You can verify this by running a production build of your reproduction and see that there won't be any detached nodes.

The leak is therefore caused by something else and needs a valid reproduction.

@yyx990803
Copy link
Member

I tend to disagree @yyx990803. In my "large" application, the v-for iterates on some dynamic user input elements. Because of these detached elements, the memory increases and increases indefinitely.

I'm speaking specifically about this reproduction. If you have a memory leak case, please provide a reproduction. Even a full application could work.

@LinusBorg LinusBorg added the need more info Further information is requested label Jan 10, 2024
@peter-gy
Copy link
Author

Then unfortunately, your demo isn't showing the actual culprit because the detached elements you see are retained by __vnode properties which are only attached in development mode for devtools usage. You can verify this by running a production build of your reproduction and see that there won't be any detached nodes.

The leak is therefore caused by something else and needs a valid reproduction.

Thank you for the clarification. I can confirm that the described problem is not present in a production build. After further investigation on our side, this might really be a duplicate of #5256. Thanks a lot for having this issue reopened and for discussing the details though.

@yyx990803
Copy link
Member

Closing this one for now then - please open a new issue if you find out the root cause of your leak is still from Vue core.

@peter-gy
Copy link
Author

Closing this one for now then - please open a new issue if you find out the root cause of your leak is still from Vue core.

We had multiple leak sources, but running the tests using a production build as per your suggestion and patching the leak in a Vuetify component (vuetifyjs/vuetify#19024) seem to have solved our issues.

@github-actions github-actions bot locked and limited conversation to collaborators Jan 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need more info Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants