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

Memory Leak - Detached Dom Element On Every Route #1489

Closed
michaelperel opened this issue Jul 27, 2022 · 1 comment
Closed

Memory Leak - Detached Dom Element On Every Route #1489

michaelperel opened this issue Jul 27, 2022 · 1 comment

Comments

@michaelperel
Copy link

michaelperel commented Jul 27, 2022

Version

4.1.2

Reproduction link

blogs.windows.com

Steps to reproduce

Use the demo app that gets installed when you run:

npm init vue@3

(say yes to installing the router)

Repeatedly click "Home" and "About" routes. In Chromium Edge devtools, select "Detached Elements"

Notice that every click results in a new detached element (the view that was being switched away from). When you click the garbage icon, and the refresh icon, note that these detached elements are never garbage collected.

What is expected?

Properly garbage collected html elements

What is actually happening?

Elements are being retained, not garbage collected. A memory leak occurs as a result.

memory_leak

This may be somewhat related to #730 . It was closed without resolution.


This causes problems for long running SPAs. For instance, I built a PWA and after a few days, it must be reloaded.

@posva
Copy link
Member

posva commented Jul 27, 2022

Hello! I checked again using the reproduction from the previous issue and it didn't yield any memory leaks.

I also tried creating a new project with npm init vue, building for production and serving the dist folder. Same result: node count is stable.

Screenshot 2022-07-27 at 09 29 47
Screenshot 2022-07-27 at 09 29 57
(Edge 103)

As you can see only one about page is cached (probably for performance reasons by the browser or Vue) and the home page isn't (probably because it's only one node)

These are the components I tried (simplified after creating the project) so you can check it yourself:

App.vue

<template>
  <header>
    <div class="wrapper">
      <nav>
        <RouterLink to="/">Home</RouterLink>
        <RouterLink to="/about">About</RouterLink>
      </nav>
    </div>
  </header>

  <hr />

  <RouterView />
</template>

HomeView.vue

<template>
  <main>Home</main>
</template>

AboutView.vue

<template>
  <div class="about">
    <h1>This is an about page</h1>
  </div>
</template>

<style>
@media (min-width: 1024px) {
  .about {
    min-height: 100vh;
    display: flex;
    align-items: center;
  }
}
</style>

Keep in mind you could also have an extension creating memory leaks.

Also please don't open issues without a reproduction. Especially memory leak issues. Always provide fully boiled down reproductions that lead to memory leaks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants