V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
rabbbit
V2EX  ›  问与答

Vue 的 keep-alive 会导致内存泄漏?

  •  
  •   rabbbit · Apr 7, 2019 · 3521 views
    This topic created in 2578 days ago, the information mentioned may be changed or developed.

    具体表现为切换路由时,exclude 中不需要缓存的 component 无法被释放,还保存在内存中.

    keep-alive 代码如下

    <keep-alive :include="['shop']" :exclude="['album']">
      <router-view ref="router"></router-view>
    </keep-alive>
    

    include 中的 shop 是一个需要被缓存的页面

    exclude 中的 album 是一个不需要被缓存

    在 shop 和 album 多次切换后, 可以发现 heap snapshot 中有大量没有释放的 vue component.

    初始的 snapshot 1

    多次切换路由后的 snapshot 2, 可以看到大量未释放的 component

    我找到了一个相关的issue.
    但是官方认为这个 bug 已经被修复了

    有人遇到过这个问题吗,有什么解决办法吗?

    Supplement 1  ·  Apr 9, 2019
    Supplement 2  ·  Apr 23, 2021
    该 bug 已被修复 https://github.com/vuejs/vue/pull/12015
    将会在版本 2.6.13 发布
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3180 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 14:29 · PVG 22:29 · LAX 07:29 · JFK 10:29
    ♥ Do have faith in what you're doing.