For the More Curious: Memory Management and Blocks
There are some subtle rules when it comes to managing memory for blocks. To understand how the block manages memory, you must understand the difference between the heap and the stack portions of memory.
To allocate memory from the heap, you must explicitly do so. Typically, this is done by sending the message alloc to a class, but it is also done when you call malloc or one of its friends. Sometimes, this happens in the implementation of another function or method, like UIGraphicsBeginImageContextWithOptions (because it calls malloc). When you allocate memory from the heap, it is your responsibility to clean it up. This is done by deallocating an object, freeing a malloc’ed buffer, or calling ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access