But after you invoke the function, the GC needs to collect it, no?
var hello = sayHi();
hello('Gandhi'); <=== I'm done
If we were in the global scope you are right, but if I'm within a scoped module, it will released the memory as soon as the second line execute.
As long as the โhelloโ variable is in reference ( global or modular ), it will keep leaking memory.
You can run the hello function yourself and see memory usage increasing.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
But after you invoke the function, the GC needs to collect it, no?
var hello = sayHi();
hello('Gandhi'); <=== I'm done
If we were in the global scope you are right, but if I'm within a scoped module, it will released the memory as soon as the second line execute.
As long as the โhelloโ variable is in reference ( global or modular ), it will keep leaking memory.
You can run the hello function yourself and see memory usage increasing.