 In both these cases, the memory manager (garbage collector) of the runtime environment (virtual machine) is unable to manage the external memory (there is no shared memory management), and thus the external memory is treated as a resource, and managed analogously.However, cycles between systems (JavaScript referring to the DOM, referring back to JavaScript) can make management difficult or impossible.A key distinction in resource management within a program is between "stack management" and "heap management" – whether a resource can be handled like a stack variable (lifetime is restricted to a single stack frame, being acquired on entry to or within a particular scope, and released when execution exits that scope), or whether a resource must be handled like a heap variable, such as a resource acquired within a function and then returned from it, which must then be released outside of the acquiring function.