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?

3
  • 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. - nodejs.org/api/buffer.html#buffer_class_buffer Commented Jan 16, 2020 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. Commented Jan 16, 2020 at 16:32
  • Does this answer your question? stack and heap in V8 ( JavaScript) or How variables are allocated memory in Javascript? Commented Jan 16, 2020 at 16:35

1 Answer 1

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."

Sign up to request clarification or add additional context in comments.

1 Comment

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.