I am currently working with a nodejs project where one of the controller looks following
var express = require('express'),
router = express.Router(),
blah = require('blah'),
Foo = require('../models/foo');
/* Get all foos */
router.get('/', function (req, res) {
Foo
.getAll()
.then(function (foo) {
return res.json({
foo: blah(foo)
});
})
.catch(function (err) {
//handle error;
});
});
/*
* Some other functions
*
*/
The required module blah and the model Foo are used inside router endpoint. According to this article http://www.ibm.com/developerworks/library/wa-memleak/, I assumed it will not be collected by garbage collector because of it being referenced by a closure inside it and might create a memory leak.
In that case what is the right way of releasing the memory?