This repository has been archived by the owner. It is now read-only.

readFile memory usage keeps rising #3609

terrywh opened this Issue Jul 2, 2012 · 5 comments


None yet
5 participants

terrywh commented Jul 2, 2012

var fs = require('fs');

setInterval(function() {
    fs.readFile("/tmp/error2.log",function(error,data) {});

at first the memory usage will be stop at 20Mb ( goes up to 50Mb and drop back down to 20Mb) for a while. and later it will reach 57Mb ( goes up to 69 Mb and drop back down to 57Mb).
when i wait about 6 minutes it stops at 124Mb. (updated: 1 hour later it grows up to 180Mb)
but i use the same code on Windows, i get 10Mb (goes up to 52Mb and drop back down to 10Mb) .
the error2.log file is about 90Kb
I wonder if the memory usage will keep rising , and why? Can i reduce the memory usage?

@terrywh terrywh closed this Jul 2, 2012

@terrywh terrywh reopened this Jul 2, 2012


domenic commented Jul 2, 2012

We have noticed the same memory leak pattern---including how it only occurs on Linux, but works great on Windows. Although, for us it was in piping some HTTP streams around, so it seems unlikely to be related.


bnoordhuis commented Jul 2, 2012

As far as I can tell no memory is actually leaked. V8 reclaims the memory but it keeps growing the heap size so it doesn't have to GC as often.

A more interesting question is why memory usage on Windows is so low. @piscisaureus Ideas?

Sannis commented Jul 3, 2012

@terry-wu you can add gc() call after fs.readFile and run this script via node --expose-gc to ensure that this is only V8 GC effect.

terrywh commented Jul 3, 2012

i tried gc() with --expose-gc and it worked well. But still why memory usage on Windows is so low? Can node do the same on Linux?

Ran this with --expose-gc and --always-compact for about an hour and saw no unexpected behavior. Closing this for now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.