Stack vs Heap

NSString *str1 = “hasancan”

NSString *str2 = str1

Here str1 and str2 are variables and are allocated in the stack. They both point to same NSString object. And NSString object is allocated in the heap.

Stack is automatically cleaned when the stack frame is popped. However you need to manage heap memory to clean it.

Leave a comment