Hi
What is the difference between Heap and Stack?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 18, 2011, 7:29 PM EST
Stack
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
Heap memory stores all instances or attributes, constructors and methods of a class/object.
Comparison
A Heap reference is also stored in Stack memory until the life cycle of the object has completed. Inside the Heap reference all the the contents of the object are stored whereas with a local variable only the variable contents are stored in the stack.
Refer the below link also
http://www.programmerinterview.com/index.php/data-structures/difference-between-stack-and-heap/
Thanks
Datta KharadRank #2,135 · 668 reputationPosted Nov 18, 2011, 7:47 PM EST
Heap and Stack:-
Procedural programming languages that let you to create variables dynamically at run-time use two different areas of Ram for holding variables;. the stack and the heap. The heap is basically all unallocated memory.
Vineet Kumar SainiRank #257 · 9.8K reputationPosted Nov 19, 2011, 12:09 AM EST
The difference betweeb Heap and Stack are as follows
when you use new or malloc() the memory is normally allocated from the heap. When you allocate an object within a function, it goes on the stack.
Heap memory stores all instances or attributes, constructors and methods of a class/object.
Stack memory is referred as temporary memory.
Heap memory is referred as permanent memory.
The heap (also known as the free store) is a large pool of memory used for dynamic allocation.
Stack is used for local variables.
Heap is used for dynamic memory allocation.
Stack is maily used for value types[ Ex : value datatypes in C# ].
Prabhu RajaRank #861 · 2.6K reputationPosted Nov 19, 2011, 1:31 AM EST
C# Heap(ing) Vs Stack(ing) in .NET: Part I, II, III and IV
http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory01122006130034PM/csharp_memory.aspx
http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory2B01142006125918PM/csharp_memory2B.aspx
http://www.c-sharpcorner.com/UploadFile/rmcochran/chsarp_memory401152006094206AM/chsarp_memory4.aspx
http://www.c-sharpcorner.com/UploadFile/rmcochran/csharp_memory_401282006141834PM/csharp_memory_4.aspx
Sam HobbsRank #107 · 20.5K reputationPosted Nov 19, 2011, 11:12 PM EST
VulpesRank #55 · 29.2K reputationPosted Nov 20, 2011, 12:04 AM EST