Skip to main content

Command Palette

Search for a command to run...

Stack and Heap Memory

Updated
2 min readView as Markdown
Stack and Heap Memory

Stack memory is the space allocated for a process where all the function calls, primitive data types (int, double, string...)

VS

Heap memory is used to store the objects that are created during the execution of a program.

Thanks for concepts about reference vs primitives type and heap/stack too! 3:39 string is primitive (copy by value) 6:47 object ,array are references type 7:05 primitives are store on stack 7:35 references are store on heap (take longer to access, store bigger amount of data) 8:40 stack (store like stack 'push on top') 9:16 heap (store pointer) 10:48 it assign a pointer not value 14:50 Object.assign create new object and merge with existing one 16:07 Object.assign doesn't deep clone 17:26 may use Lodash to clone instead 19:04 copy array

Screenshot (264).png

Screenshot (263).png

img_5b73d7f592aa2.png

main-qimg-1a1dbbe8b343484a55f3ff386b9cb48a-pjlq.jpg

1_OGHcuzHaFL8Rz7gL17PriQ.png

Screenshot (272).png

Element (object) is created in the heap which store the actuall object, But we do have a pointer on the stack which stores the reference ,the address to this object in the heap and the variable simply store the pointer. The varaible doesn't know the address of the place in memory where our object is stored but the variable knows where the pointer lies on the stack it knows the position of the pointer on the stack an the pointer in turn simply stores the address of the object in the heap.

Screenshot (274).png

Screenshot (275).png

More from this blog

Omar's blog

135 posts