0

I was learning JavaScript and wanted to understand how memory allocation works in the language thus I came across the term memory heap being a location where data is kept. The question is:

Is it true that any type of value be it simple number or huge data structure are kept in memory heap only?

wewq
  • 229
  • 3
  • 11
  • Buffer data is stored outside of the main V8 heap: *Instances of the Buffer class are similar to arrays of integers from 0 to 255 (other integers are coerced to this range by & 255 operation) but correspond to fixed-sized, raw memory allocations outside the V8 heap.* - https://nodejs.org/api/buffer.html#buffer_class_buffer – nopassport1 Jan 16 '20 at 16:29
  • ECMAScript, the standard on which JavaScript is built, does not determine a memory structure to use, so this will be up to each implementation. – Heretic Monkey Jan 16 '20 at 16:32
  • Does this answer your question? [stack and heap in V8 ( JavaScript)](https://stackoverflow.com/questions/6602864/stack-and-heap-in-v8-javascript) or [How variables are allocated memory in Javascript?](https://stackoverflow.com/q/2800463/215552) – Heretic Monkey Jan 16 '20 at 16:35

1 Answers1

0

The term, "heap," generally refers to an area of memory where things of arbitrary size and purpose are kept, and from which storage is dynamically allocated and released as needed. JavaScript makes extensive use of this for everything it does: variables come into existence for a time, then go away. You can create objects and simply forget about them. Periodically, a "garbage collector" runs through and reclaims things that are no longer actively referenced. All of this sort of thing is what is commonly referred to as "a heap."

Mike Robinson
  • 8,490
  • 5
  • 28
  • 41
  • thank you for your kind answer, the reason for asking the question was that some say variables with simple value are kept in call stack itself but larger values are kept in memory heap. Is that true? or can I safely think that all types of values are kept in memory heap? – wewq Jan 16 '20 at 16:33