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. Stack and heap
Ashwin Anand V
Email:ashwinanand99@gmail.com
Facebook id:ashwinanand99@gmail.com
4. Difference between instance
variables and local variables
• Instance variables are declared inside a class but not
inside a method:
class Student{
int num; // num is instance variable
public void showData{}
• Local variables are declared inside a method
including method arguments:
public void sum(int a){
int x = int a + 3; // a , x are local variables
•
• }
5. What goes inside when you
declare a variable?
• When you declare a variable in a application, it
allocates some chunk of memory in the RAM.
• This memory has three things: the name of the
variable, the data type of the variable, and the value
of the variable.
6. STACK
• The Stack section of memory contains methods,
local variables and reference variables.
• All the information required to resume the execution
of these functions is stored on the stack.
• Provides static memory allocation
7. HEAP
• The heap is simply 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 .
8. Example for stack and heap
public void Method()
{
int i=4; (stack memory)
int y=2 (stack memory)
Class1 cls1= new class(); (heap memory)
}
10. • If this presentation helped you, please visit
our page facebook.com/baabtra and like it.
Thanks in advance.
• www.baabtra.com | www.massbaab.com |ww
w.baabte.com