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 in Vue.js server-side when using "computed" #5975

Closed
freeozyl80 opened this issue Jun 26, 2017 · 6 comments
Closed

Memory leak in Vue.js server-side when using "computed" #5975

freeozyl80 opened this issue Jun 26, 2017 · 6 comments
Labels

Comments

@freeozyl80
Copy link

Version

vue@2.2.3

Reproduction link

https://github.com/freeozyl80/vue-memory-leak

Steps to reproduce

  1. use Vue Server Render (renderToString);
  2. the vm in server has "computed" which define a test function without return.(yes ,this step is incorrect, just throw error and pause is ok, but then memory leak happend)
  3. memory leak happend.

What is expected?

throw error and pause

What is actually happening?

the vonde is going to run and create, but not destroyed and exit.
In heap snapshots, i found the vue$2 has created almost 4538


just look in 'https://github.com/freeozyl80/vue-memory-leak'

@HerringtonDarkholme
Copy link
Member

Hi, I have cloned your repository. Wrapping your code in a while (true) statement does not incur out of memory error. This probably means nothing wrong with library code.

Note the memory consumption in your snapshot is under 200MB, which is fairly a low work load for server code. So it is reasonable V8 does not reclaim these memory.

Can you provide more information?

@freeozyl80
Copy link
Author

i tried use setInterval, interval of 20 ms. when i run in the server, the memory used by it is increasing
914596a7-589b-43df-b432-b59fa545ac40
c2eb4468-9246-4f04-9c26-1bdf64888d31
aefb5b83-8211-4277-bed4-4c5e44a6f706
by the way, 200MB is small number, but this happened on the production enviroment when the request almost 30millon per day, fortuneately, i found the reason and made the "computed"'s function correctly. but after that, i wonder why it happend?
by the way, thanks for help

@HerringtonDarkholme
Copy link
Member

Please update your code to illustrate the problem.

@freeozyl80
Copy link
Author

alreay updated

@HerringtonDarkholme
Copy link
Member

Ok, I reproduced it. And commenting out throw new Error does keep memory low.

@HerringtonDarkholme
Copy link
Member

HerringtonDarkholme commented Jun 28, 2017

Reproducible in browser.

var timer = setInterval(function() {
    const vm = new Vue({
        computed: {
            "test": function() {
                throw 'erro happened';
            }
        }
    });
    try {
        vm.test
    } catch(e) {
    }

}, 1);

HerringtonDarkholme added a commit to HerringtonDarkholme/vue that referenced this issue Jun 28, 2017
watcher.get should always clean up observee stack in order to prevent memory leak. Also, non-user
defined watch should rethrow error.

vuejs#5975
jskrzypek pushed a commit to jskrzypek/vue that referenced this issue Jul 6, 2017
watcher.get should always clean up observee stack in order to prevent memory leak. Also, non-user
defined watch should rethrow error.

fix vuejs#5975
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

2 participants