My app is up and running on heroku on 5 parallel dynos. There is constant load of 500-1500 req/min so up to 25 req/sec. The problem is that RSS memory is constantly growing. For now I am manually restarting app when memory reaches dangerous level (maximum memory used by 1 heroku dyno is 512mb). Memory chart looks like this (upper gray axis is at 512mb limit):

Moments (on chart) when memory is released are when I am restarting app.
The strange thing is that it happens only when there is constant load on server. When there is for example 2 minutes load on server then memory increases and after that in goes down again. So it seems that for some reason garbage collector is not working properly (it is no collecting the garbage until server load is finished and app is not busy).
Is there anything I can do about it? It is not memory leak I think because memory is released when there is no load on a server...
What I tried so far was:
Maybe there are other options that could help?
Node version is 0.10.20
I used node memwatch package and I managed to gather heap diffs from app:
So there must be kind of leak I guess. The biggest memory changes from first diff:
...
{
"what": "Array",
"size_bytes": 9320312,
"size": "8.89 mb",
"+": 79086,
"-": 10215
},
...
{
"what": "Closure",
"size_bytes": 2638224,
"size": "2.52 mb",
"+": 36826,
"-": 184
},
{
"what": "Native",
"size_bytes": 21471232,
"size": "20.48 mb",
"+": 546,
"-": 0
},
{
"what": "String",
"size_bytes": 2068264,
"size": "1.97 mb",
"+": 36968,
"-": 1223
},
...
What is Native object (it allocated 20mb mem!)? Could you give me advice on how to investigate what exactly is causing the leak?
I had a similar problem once where i was constantly querying data from mysql. We Can not really help you without any code, but still you are getting constant memory growth, then you should dig into the code and find out if you have some loops where you are generating or receiving large data, in form of variables..
The problem was fixed by simply not using postgres native bindings (https://github.com/brianc/node-postgres#native-bindings). When I stopped using native bindings (I am using Sequelize.js so I just changed native flag to false) memory started to behave normally...
It seems that there might be leak in pg native bindings?