Skip to content

Commit

Permalink
renderer: patch keep-alive to fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
rocka committed Apr 1, 2020
1 parent 591f358 commit f12a5eb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/renderer/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<AppNav></AppNav>
<div class="router-view">
<transition :name="transitionName">
<keep-alive :include="KeepAlive">
<keep-alive-patched :include="KeepAlive">
<router-view></router-view>
</keep-alive>
</keep-alive-patched>
</transition>
</div>
<PlayerBar></PlayerBar>
Expand Down
2 changes: 2 additions & 0 deletions src/renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import routes from './routes';
import { isLinux } from './util/globals';
import { initTheme } from './util/theme';
import DblclickRipple from './util/dblclick-ripple';
import KeepAlivePatched from './util/keep-alive-patched';
import './style.css';
import './transition.css';
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css';
Expand All @@ -21,6 +22,7 @@ Vue.use(MuseUI);
Vue.use(Toast);
Vue.use(Message);
Vue.use(DblclickRipple);
Vue.use(KeepAlivePatched);
Vue.component('RecycleScroller', RecycleScroller);

try {
Expand Down
19 changes: 19 additions & 0 deletions src/renderer/util/keep-alive-patched.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export default {
/**
* @param {Vue.VueConstructor} Vue
*/
install(Vue) {
const KeepAlive = Vue.component('KeepAlive');
Vue.component('keep-alive-patched', {
extends: KeepAlive,
updated() {
const { _vnode, cache } = this;
for (let key in cache) {
if (cache[key] && cache[key].parent && (cache[key].tag != _vnode.tag)) {
cache[key].parent = null;
}
}
}
});
}
};

0 comments on commit f12a5eb

Please sign in to comment.