Tuesday , 27 September 2022
Breaking News
Home » Science/Tech » Newbie point » Difference between Stack vs Heap memory

Difference between Stack vs Heap memory

Stack memory stores variable types in address’ in memory, these variables in programming are called local variables and are often stored for short amounts of time while a function/method block uses them to compute a task.

Once a function/method has completed its cycle the reference to the variable in the stack is removed.
Heap memory stores all instances or attributes, constructors and methods of a class/object.

A Heap reference is also stored in Stack memory until the life cycle of the object has completed. Inside the Heap reference all the contents of the object are stored whereas with a local variable only the variable contents are stored in the stack.


var blue
var red
ref 0x456783 (Heap reference)
var tom
ref 0x498702 (Heap reference)
var diane

Heap (0x456783)
name => Susan
age => 26
city => London
height => 5’7
Gender => female

Heap (0x498702)
name => Paul
age => 21
city => Glasgow
height => 6’0
Gender => male

Related stories:

Fans Pay Tribute to MJ in London where he was to Perform
Michael Jackson “This is it” Movie to hit theatres
Harry Potter and the Deathly Hallows LIVE premiere 2010
The Rock got Mad at me, tweets John Cena
World's Oldest Panda dies at 34
London : Christmas promises a big Shopping rush!
First-Ever Color Film Revived by UK Museum!
Amy Winehouse Didn't Die From Alcohol Poisoning???