So I've read about the stack and heap recently and how are they managed in runtime, but there's a case that's been bothering me, since I have a specific usecase in my test suites.
For example,
function foo(myOjb) {
myObj.fooMethod();
}
In the code above, I'm creating a reference to an already existing object instance, which in my particular case is responsible for creating http interceptors. I run this type of functions several times within a single test, since I'm delegating the logic for creating those interceptors to another functions, instead of writing them line by line in my suites to avoid too much boilerplate, repetition and improve readability. So my question is - are all of those resources freed when each function exits (returns undefined)? I'm asking this because the object itself still exists in memory and I became afraid that I'm using up too many resources with such a reckless approach.