I've done some tests with my node.js application looking for memory leak that my code supposed to do. I run script that in my opinion should leak memory, but I am surprised by the result.
redisClient.on('message', initRequest);
function onSuccess(self, json){
console.dir(json);
}
function initRequest(channel, message){
var request = new RequestObject({
redisMessage: message
});
request.on('success', onSuccess);
}
redisClient emits a couple of 'message' events per second. This mean that initRequest function is called quite often. Each time request object is created in memory, and function onSuccess is bind to its 'success' event.
I assumed (but here I may be wrong), that as far as there is listener (onSuccess in this case) bind to this object it cannot be garbage collected. Then I thought, memory usage will grow since memory won't be free-ed up.
As a solution for this potential leak I wanted to use .once instead of .on, as this will unbind listener and object could be garbage collected.
I've used pmap to test both scenarios (comparing .on and .once and one another scenario that is not worth to mention here), and I haven't found a big difference.

To sum up I have 2 questions:
Is this normal GC behavior to clean memory in some intervals, or after it reach some threshold instead of continuous cleaning?
Am I correctly assume that example code with
.onshould leak memory, which I don't see on memory consumption graph?
RequestObjectand got nothing interesting.