question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Memory leak when using "transition" and "keep-alive"

See original GitHub issue

Version

2.6.10

Reproduction link

https://codepen.io/aaronbird/pen/JVRKwa

Steps to reproduce

I wrote a demo:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>demo</title>
    <style>
      .link {
        cursor: pointer;
        user-select: none;
      }
    </style>
  </head>
  <body>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>

    <div id="app">
      <transition>
        <keep-alive include="foo">
          <component :is="target" @change="onChange"></component>
        </keep-alive>
      </transition>
    </div>
    <script>
      const Foo = {
        name: "foo",
        template: `<div class="link" @click="$emit('change', 'bar')">Go to Bar</div>`
      };
      const Bar = {
        name: "bar",
        template: `<div class="link" @click="$emit('change', 'foo')">Go to Foo</div>`
      };
      Vue.component("foo", Foo);
      Vue.component("bar", Bar);
      const app = new Vue({
        data: {
          target: "foo"
        },
        methods: {
          onChange(target) {
            this.target = target;
          }
        }
      }).$mount("#app");
    </script>
  </body>
</html>

The debugging process is as follows:
1 Click “Collect garbage” and “Take heap snapshot”(snapshot 1)
2 Click the routing button on the left 10 times, then click “Collect garbage” and “Take heap snapshot”(snapshot 2)
3 Click the routing button on the left 10 times, then click “Collect garbage” and “Take heap snapshot”(snapshot 3)

The generated “snapshot” is as follows:

snapshot 1:
snapshot 2:
snapshot 3: After clicking 100 times:

VueComponent is not being recycled, is this a bug?

What is expected?

Why is this happening, is this a bug?

What is actually happening?

Component will not be cleared when switching components.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kadet1090commented, Jan 19, 2020

I’d really love to see any update on this issue - there is PR but it seems dead?

2reactions
sky8ezcommented, Jan 6, 2020

Hey, is there any news? is this updates already merged to master branch ? I have the same problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory leak when using "transition" and "keep-alive" - CodePen
URL Extension Required. When linking another Pen as a resource, make sure you use a URL Extension of the type of code you...
Read more >
When and why does MobX's keepAlive cause a memory leak?
So, in theory, an active autorun can cause a memory leak just like keepAlive: true . In practice, this is very unlikely. For...
Read more >
VueJS Memory Leak when Switching Routes - Stack Overflow
On every route changed, whole lotta VueComponent is added to the dom/but no one is deleted. A quick fix for that is using...
Read more >
Memory leak: How to avoid it in Vue js - ArrowHiTech
In this case, you can use the built-in component keep-alive. When you wrap a component with keep-alive , its state will be preserved...
Read more >
Causes of Memory Leaks in JavaScript and How to Avoid Them
A memory leak occurs when an object in memory that is supposed to be cleaned in a garbage collection cycle stays reachable from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found