One, memory management type definition
1, the basic type of any C type, eg:
Int,short,char,long,long long,struct,enum,union are basic types or structures
Memory management is not valid for the basic type of C language
2,OC type (non-basic type)
Any object that inherits from the NSObject class belongs to the OC type
Which is the other type except for C.
Second, OC object structure
All OC objects have a counter that retains the number of references to the current object, and if the counter is 0, the object is actually freed.
Three, alloc retain release function
1, the Alloc function is created using the object, and the counter is 1 after creation (only once)
Retain is counter +1 to an object (can be called multiple times)
Release is a counter to an object-1 (minus 0 objects will be freed from memory)
A reference counter is implemented in the 2,oc class, and the object knows the number of times it is currently referenced.
If you need to reference an object, you can send an retain message to the object so that the object counter is + 1;
When you do not need to reference the object, you can send the release message to the object, so that the object counter is-1;
When the counter is reduced to 0, the object's Dealloc function is automatically called, and the object frees the memory;
Objects with a counter of 0 can no longer use release and other methods.
IV, automatic release of the pool
The auto-free pool is an automatic memory recovery mechanism for OC, which can be used to collect temporary variables through the automatic release pool.
When the auto-release pool itself is destroyed, all objects inside the pool do a release operation once.
Any OC object that calls the Autorelease method will place the object in its closest auto-release pool (the release pool at the top of the stack).
Five, not an object created with Alloc,retain,copy, cannot be released with release.
Memory management of iOS learning notes