ReAlloc Dynamic Memory Tuning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.