There are three main areas of memory used by C programs (and by extension, Objective-C) to store data:
- Static Area
- Auto region (also known as "stack") and
- The dynamic region (also known as the heap).
When you alloc objects by sending your class a new or alloc message, the resulting object is allocated in the dynamic storage area, so the object is said to live on the heap. All Objective-C objects are similar (although pointers that reference these objects can be in any of the three memory data areas). In contrast, primitive local variables and arrays "live" on the stack, while global primitive variables and arrays live in a static data store.
Only heap objects are counted by reference, although you can allocate memory from the heap using malloc / calloc / realloc , in which case the allocation will not be counted: your code will be responsible for deciding when the allocated dynamic memory is free .
source share