You do not care about the stack against the heap and about freeing up memory. This happens automatically, as Node.js offers an accurate trash garbage collector. Some data is stored in the GC heap. Some data is on the stack. You cannot say at all, because it depends on optimizations performed by the JIT compiler at runtime. Profiling tools can provide permeability to applications.
For non-memory resources (like files and sockets), use finally :
var file = open(…); try { … } finally { close(file); }
source share