What does it mean to live on a heap?

I am learning Objectiv C, and I constantly hear the term “live on the heap”, based on the fact that I understand it is some unknown area in which the pointer lives, but trying to actually put an end to the exact term ... like " we need to make our property strong so that it doesn’t live on the heap. He said that since the property is private, I know that this is a big difference. It is very clear that we want to make sure that we want to calculate the reference to this object so that the abstract did not clear it (we want to “save” it from what I know so far), but I want to make sure I, that I understand this term, because it is used quite often.

Rate it

+6
source share
1 answer

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 .

+14
source

All Articles