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 with keep-alive #6759

Closed
okjesse opened this issue Oct 9, 2017 · 23 comments
Closed

memory leak with keep-alive #6759

okjesse opened this issue Oct 9, 2017 · 23 comments
Labels

Comments

@okjesse
Copy link

okjesse commented Oct 9, 2017

Version

2.4.4

Reproduction link

https://jsfiddle.net/okjesse/k94fphsg/

Steps to reproduce

Switch Foo and home link for several times,VueComponent's count will be always grow up

What is expected?

VueComponent's count is stable

What is actually happening?

VueComponent's count always grow up

  1. switch 0 time:
    1
  2. switch 20 times:
    2
  3. switch 100 times
    3

when the component is big, chrome's memory will be not enough!

thank you for your reading!

@posva
Copy link
Member

posva commented Oct 9, 2017

Tested with latest vue build and seems to still be the case when using include. I removed Vue Router as well. For memory leaks, it's better to provide html pages as the heapshot is way way faster to take:

<!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>Document</title>
</head>

<body>
  <script src="https://npmcdn.com/vue/dist/vue.js"></script>

  <div id="app">
    <button @click="comp = 'Home'">/home</button>
    <button @click="comp = 'Foo'">/foo</button>
    <keep-alive include="Foo">
      <component :is="comp" />
    </keep-alive>
  </div>

  <script>
    const Home = {
      name: 'Home',
      template: '<div>{{text}}</div>',
      data: function() {
        return {
          text: 'home'
        }
      },
    }
    const Foo = {
      name: 'Foo',
      template: '<div>{{text}}</div>',
      data: function() {
        return {
          text: 'Foo'
        }
      },
    }


    new Vue({
      el: '#app',
      data: {
        msg: 'Hello World',
        comp: 'Home'
      },
      components: {
        Home,
        Foo
      }
    })
  </script>
</body>

</html>

Removing the include prop stops the object count increment but keeps the increment of the retained size of the keep-alive component which I'm not sure is intended

Edit by @HerringtonDarkholme: add repro link https://jsfiddle.net/a5qb0m8u/1/

@posva posva added the bug label Oct 9, 2017
@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Oct 9, 2017

My preliminary investigation tells me there is a discrepancy between the cached VNode and its parent.

The children in parent's componentOption contains stale child, in this case Home. Thus the entire list of component instances isn't collected.

@posva
Copy link
Member

posva commented Oct 9, 2017

I haven't investigated further, just tried to guess from reading keep-alive component but it could also come from some other place. I'm interested in the fix though, memory leaks are interesting in js 😄

@okjesse
Copy link
Author

okjesse commented Oct 9, 2017

https://jsfiddle.net/a5qb0m8u/1/ The code seems still has this problem after test.

@okjesse
Copy link
Author

okjesse commented Oct 10, 2017

Thank you very much, It's works!

@denonzhu
Copy link

denonzhu commented Mar 2, 2019

这个问题好像还没有有效的解决,在动态incloud的时候 ,已经缓存的组件被删除后,在实际内存中还是没有被清除,chrome 内存快照依然能看到detach的vnode。最新版本2.6.7

@love1390700626
Copy link

这个问题好像还没有有效的解决,在动态incloud的时候 ,已经缓存的组件被删除后,在实际内存中还是没有被清除,chrome 内存快照依然能看到detach的vnode。最新版本2.6.7

我也遇到了,有什么办法可以解决吗。

@hunson1990
Copy link

这个问题好像还没有有效的解决,在动态incloud的时候 ,已经缓存的组件被删除后,在实际内存中还是没有被清除,chrome 内存快照依然能看到detach的vnode。最新版本2.6.7

同遇到,请问有什么解决方案么

1 similar comment
@381510688
Copy link

这个问题好像还没有有效的解决,在动态incloud的时候 ,已经缓存的组件被删除后,在实际内存中还是没有被清除,chrome 内存快照依然能看到detach的vnode。最新版本2.6.7

同遇到,请问有什么解决方案么

@caosy8023
Copy link

我也遇到了,求解决方法

@yjq8023
Copy link

yjq8023 commented Dec 23, 2019

楼上大佬们有解决办法了么?

@amormason
Copy link

@yjq8023 大佬有处理办法了吗?

@yjq8023
Copy link

yjq8023 commented Dec 24, 2019 via email

@amormason
Copy link

@yjq8023 网上有办法修改 node_modules\vue\src\core\components\keep-alive.js 这个源码的代码的解决办法 问题是我怎么修改这个文件都无效 甚至把这个文件清空了 程序还是一样的运行 如果有办法修改这个文件 估计可以试试

@yjq8023
Copy link

yjq8023 commented Dec 24, 2019 via email

@yjq8023
Copy link

yjq8023 commented Dec 24, 2019 via email

@yjq8023
Copy link

yjq8023 commented Dec 25, 2019 via email

@namehou
Copy link

namehou commented Apr 7, 2020

我也遇到了这个问题 急需解决方法? 标签页面关闭,内存不销毁

@jiaozhiye
Copy link

我也遇到了这个问题 急需解决方法? 标签页面关闭,内存不销毁

@liwenda122
Copy link

same probelm

@alwxkxk
Copy link

alwxkxk commented Nov 18, 2021

经测试,2.6.10仍存在内存泄漏问题,但2.6.14已经没有了。
应该是#10085已修复并合并了。

@JinPengGeng
Copy link

10085 只是合并到 dev 分支,并没有 release 在 2.6.14 的版本中
看官方计划是在 2.6.15 的release中,状态已经完成,但还有不少其他的 Planned 没有结束
我也在等待中。。。
https://github.com/vuejs/vue/projects/11#column-14560638

@hanzhangyu
Copy link

hanzhangyu commented Dec 9, 2021 via email

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

No branches or pull requests