Difference between stack memory and heap memory in java

Number of View: 5836


                 Stack              Heap

1)      Used to store local variables,address of the objects and method calls.

1)      Used to store Object values in java.
2)      When there is shortage of memory in stack ,JVM throws java.lang.StackOverflowError. 2)When there is shortage of memory in heap JVM throws java.lang.OutOfMemoryError.
3)      Data in the stack dies or gets deleted once the block of code or method call terminates. 3)Data in the heap dies till the object gets garbage collected.
4)      Stack is faster when compared to heap 4)Heap is slower when compared to stack
5)      Variables created in stack are visible only to the thread which it has created. 5)Objects in heap are visible to all threads.

Thanks to interviewdot.com for the video.click here to submit your resume in interviewdot.com

No related posts.

2 comments on “Difference between stack memory and heap memory in java

  1. very nice analization!

  2. Devendar on said:

    Excellent, Very Helpful Article.

Leave a Reply

Your email address will not be published. Required fields are marked *


HTML tags are not allowed.