+ 2

What' the differences between heap and stack memory in java

7th May 2020, 7:02 AM
Thayani Gathirvelou🇱🇰
Thayani Gathirvelou🇱🇰 - avatar
4 Réponses
7th May 2020, 7:06 AM
Thayani Gathirvelou🇱🇰
Thayani Gathirvelou🇱🇰 - avatar
+ 4
Avinesh thank u🙏🙏
7th May 2020, 8:18 AM
Thayani Gathirvelou🇱🇰
Thayani Gathirvelou🇱🇰 - avatar
+ 2
Any object instantiated with a 'new' keyword gets memory allocated on the heap and the memory deallocation is taken care by the garbage collector in Java. Also string literals are stored on the heap in a separate space known as String Constant Pool (SCP). All the instance and local variables are allocated memory on the stack. Also the stack memory is just few mb's whereas the heap is considered as infinite space of memory.
7th May 2020, 8:16 AM
Avinesh
Avinesh - avatar