Search code examples
javascriptv8

stack and heap in V8 ( JavaScript)


does V8 uses stack and heap like the JVM? if so does it put primitives on the stack and objects on the heap?


Solution

  • Yes, V8 uses a heap similar to JVM and most other languages. This, however, means that local variables (as a general rule) are put on the stack and objects in the heap. This may for instance not hold if a function closes over these values. As in the JVM, primitives can only be stored on the stack if they are stored in a local variable.

    As a user it is not something you would normally need to worry about.