I have few questions related to memory usage in nodejs
In the MVC project structure, can require file increase memory uses over time? eg :
In server.js (main file i.e entry point of server)
let user = require("./routes/user-r.js") //1kb during initial run,will it increase in size as number of hit increase? app.use("/",user);
In routes/user-r.js
let user_c = new (require("../controller/user-c.js")) //1kb during initial run,will it increase in size as a number of hit increase? module.export = (app) =>{ // require above or inside below code does it make any difference in memory usage perspective? // let user_c = new (require("../controller/user-c.js")) route.get("/", user_c.Test()) }
In controller creating variable clear automatically after it returns response? eg:
In controller/user-c.js
let path = require("path") // will this increase memory size, every time when this controller call from routes class User { constructor(){ this.user_m = new (require("./user-m.js") // is constructor remove this file from memory when not in use? i.e garbage collection remove this variable from memory } Test(){ let x = "this is testing for memory" // is this variable clear from memeory every time? }
}
when garbage collection runs automatically? i.e after a certain default memory limit or after a response return by the controller
what happens if the server has continuously hit in the 10-sec interval will garbage collection runs automatically?
requiring the same file in a different variable can use twice memory size or same eg :
let t = require("path"); let c = require("path"); is both variable consume memory ?
suppose 3 controller files, consider as user-c, management-c , test-c. all these file requiring path ( require("path")) and storing it into 3 different variable. will it increase memory uses 3 times?
is it possible to make a test file that can check for memory leakage?
is there any npm packages that can check for memory usage?