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 setInterval + console.log + process.memoryUsage #2073

Closed
EricTheOne opened this issue Jun 29, 2015 · 7 comments
Closed

Memory leak in setInterval + console.log + process.memoryUsage #2073

EricTheOne opened this issue Jun 29, 2015 · 7 comments

Comments

@EricTheOne
Copy link

The following code exhibits a growth in RSS and heap over time:

setInterval(function doLog() {
    console.log(process.memoryUsage());
}, 100);

leak1

Attached image made by excel - extract measurements from above script to clipboard then:

pbpaste | grep heapTotal | cut -d " " -f 3,5,7 | pbcopy 

Why is this happening?

@JacksonTian
Copy link
Contributor

process.stdout.write buffered a lot data. Not really memory leak. You can write the data into file instead of.

@bnoordhuis
Copy link
Member

It's not necessarily indicative of a memory leak. What happens when you restrict the heap size with --max_old_space_size=32?

@EricTheOne
Copy link
Author

@JacksonTian since I see the measurements as they come on the console, doesn't it mean the buffer gets periodically flushed?

@bnoordhuis checking

@Fishrock123
Copy link
Contributor

The following code exhibits a growth in RSS and heap over time:

The graphs look normal for v8 I think. v8 like to keep as much as it can (within a specified limit, default 1gb iirc) so it doesn't have to re-allocate, is my understanding.

@trevnorris
Copy link
Contributor

1.5GB for x64 machines, but @Fishrock123 is correct. V8 feels free to use the heap it's given as freely as it wants. My experience is you can only know it's a memory leak for sure if it can cause the process to crash.

@EricTheOne
Copy link
Author

@bnoordhuis running with --max_old_space_size=32:

  1. RSS - not growing (even a small decline over time)
  2. heapTotal - stable
  3. heapUsed - slowly increasing over time and over multiple GC runs.

@trevnorris's comment means that looking at the growth in heap utilization is not enough, so I guess this behavior is normal.

@Fishrock123
Copy link
Contributor

Yeah, seems normal, that's just how newer v8 does things. Closing.

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

No branches or pull requests

5 participants