Memory problems: Probabilistic crashes
malloc: Dynamic memory allocation allocates a block of memory with a length of num_bytes bytes
Calloc: Dynamic memory allocation and 0 function: allocating n contiguous spaces of size in the dynamic storage of memory, the function returns a pointer to the assigned start address, or null if the assignment is unsuccessful.
ReAlloc Dynamic Memory Tuning
Function
First determine whether the current pointer has enough contiguous space, if there is, expand the address pointed to by Mem_address, and return mem_address, if the space is not enough, first in accordance with the size specified by newsize to allocate space, the original data from beginning to end copied to the newly allocated memory area, Then release the original mem_address memory area (Note: The original pointer is automatically freed, do not need to use free), and return the new allocated memory area of the first address. That is, the address of the memory block is redistributed.
The point in time of initialization
Point in time when releasing
1, UNSUBSCRIBE notification
2, cancel the key value observation
Manual memory Management principles: who applies for memory, who is responsible for releasing
Basic principle: Memory is not referenced, immediately released
Example: Player release
__strong: A strongly referenced, strongly referenced, type of object pointer to memory that is never freed.
__weak: Zero Weak reference: if memory, the object pointer to the weak reference type is zeroed. The memory release condition, which is not affected by this type of object pointer. When the memory that the object pointer points to is freed, the object pointer automatically resets nil (zeroed).
__weak __block roomg * copy_self = self;
ReAlloc Dynamic Memory Tuning