3

I'm creating bower package search site (everything is open sourced) and I hit the wall. I have some memory leak (or I think I have) and I honestly don't know why it is there.

You can download it and run on Your own, but simple hint will help me greatly.

I have narrowed it down to this function call here https://github.com/kamilbiela/bowereggs-backend/blob/master/main.js#L14 ( nest.fetchAndSave() ) which is all defined here: https://github.com/kamilbiela/bowereggs-backend/blob/master/lib/nest.js

Basically it downloads a package list from internet, Json.parse and inserts it into database, plus some when.js promises.

Running this function few times creates a 30mb of memory per run, that is not cleaned by garbage collector. Also note that this is my first "real" node.js project, so I'll be really grateful for any tip.

Kamil Biela
  • 706
  • 1
  • 6
  • 13
  • 1
    Oh, why did you just run that function few times? :) Let's run more times and you may see garbage collector work. – damphat Jan 02 '14 at 23:21
  • I have run this script with ``node --expose-gc main.js`` and in code: global.gc(); didn't help. Also used https://github.com/lloyd/node-memwatch and it seems that gc is ran, but memory is not cleaned after (only some small amounts). Edit: Also I discovered it only because my small vps server kills process because there is not enough memory for it. – Kamil Biela Jan 02 '14 at 23:31

1 Answers1

2

For anyone having the same problem:

https://github.com/c4milo/node-webkit-agent

After making few heap dumps I discovered that objects are garbage collected and the real memory usage isn't tied to it. I think that real memory usage is bigger because of using mongo and other non node.js stuff. Also real memory usage stabilizes at ~300mb, heap dumps at ~35mb.

Kamil Biela
  • 706
  • 1
  • 6
  • 13