2. Disclaimer: This presentation is prepared by
trainees of baabtra as a part of mentoring
program. This is not official document of baabtra –
Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System
Technologies Pvt . Ltd
3. HEAP AND STACK
vishnu.padinjattedath@gmail.com
@Vishnu_Kishor
4. BASICS
• The JVM divided the memory into following
sections.
– Heap
– Stack
– Code
– Static
• This division of memory is required for its
effective management
5. • The code section contains your bytecode.
• The Stack section of memory
contains methods, local variables and
reference variables.
• The Heap section contains Objects (may also
contain reference variables).
• The Static section contains Static
data/methods.
6. • Of all of the above 4 sections, you need to
understand the allocation of memory in Stack
& Heap the most, since it will affect your
programming efforts.
7. Difference between instance variables
and local variables
• Instance variables are declared inside a class
but not inside a method
class Student{
<strong>int num; // num is instance
variable</strong>
public void showData{}
8. • Local variables are declared inside a method
including method arguments.
1public void sum(int a)
{
int x = int a + 3;
// a , x are local variables</strong>
}
9. VARIABLE DECLARATION
• Allocation of some RAM memory to variable.
• Three aspects saved in memory
– the name of the variable,
– the data type of the variable and
– the value of the variable.
10. STACK : DEFENITION
• The Stack section contains
– methods,
– local variables and
– reference variables.
• The info: required to resume the execution of
these functions is stored in the stack.
• Provides static memory allocation
11. HEAP : DEFENITION
• The memory used by programs to store global
variables.
• All global variables are stored in heap memory
• When that function exits, the heap memory
used by each local variable is freed.
• Dynamic memory allocation