AStaroverov / v-media-query

easy media query for vue

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Memory leak prevention

aiankile opened this issue · comments

While investigating a serious memory leak issue in our Vue-SPA, I've stumbled upon instances of VueComponent still being referenced in $mq method context in spite of being already "destroyed".
This lead me to the created hook inside the mqData-mixin, containing the following line:
_vms[this._uid] = this

Here, root Vue instances are saved inside a local hash object in order to later trigger the resize-chains.
It works fine as long as all such Vue instances are completely persistent - that is, never get destroyed.
However, multiple big packages implement their functionality via dynamical Vue instances internally - creating and destroying them continuously.
Prominent examples: Vuex or vuelidate.

As a consequence, destroyed instances never get unregistered in _vms and thereby remain in memory. This issue gets quite fatal in single-page applications (SPA), e. g. in combination with vue-router, where each navigation to the same module leaves more garbage in the memory.

Locally, I've fixed this issue via a simple beforeDestroy hook:
beforeDestroy () { if (this._uid in _vms) { delete _vms[this._uid] } }

Should I open a PR for this?

Thx, its real big mistake, im fix it ASAP;

Fixed and published, thx for issue!