As I understand , in Java, Stack memory holds primitives and method invocations and heap memory is used to store objects .
Suppose I have a class
class A {
int a ;
String b;
//getters and setters
}
where will the primitive 'a' in class A be stored ?
Why does heap memory exist at all ? Why cant we store everything in stack ?
When the object gets garbage collected , is the stack associated with the objected destroyed ?