Skip to content Skip to sidebar Skip to footer

Heap And Native Memory Allocation In JavaScript: How Managed?

JavaScript has Heap (garbage collected) memory, and Native (Typed Arrays, DOM elements) memory. Question: is there a balance between the two so that if I want to have a LOT of type

Solution 1:

If you're trying to minimize memory usage and your code lends itself to typed arrays, then a typed array should use less memory than a regular array. All this memory comes from the same place so your question about heap vs. native doesn't really make sense to me. The more memory you use for typed arrays, the less memory you will have available for anything else that uses memory. Your best bet at optimization is to just use less memory and not worry about what kind of thing is using that memory as memory is memory whether it has a typed array in it or a giant string in it.

Typed arrays are garbage collected just like regular arrays. Typed arrays are more memory efficient only because they use less storage for each element in the array, not because they use a different type of memory.


Post a Comment for "Heap And Native Memory Allocation In JavaScript: How Managed?"