Generally heap and stack are datastructures and it is applied in memory management effectively .
Stack as you know is last in first out so whenever something is pushed or poped out it effects the elements added recenlty
whereas heap is a collection of datas all datas are grouped as a heap you can remove any element which is not needed from the heap and can allocate memory from heap if it has free memmory and this way you can achieve memory management(using delete and new)