The 16th chapter of the book on the operation of the file and directory, the content is relatively simple, again skipped.
The 17th chapter of the study notes by myself summarized and presented to you.
Memory Management:
-Use memory management to clean up unused memory in order for the memory to be used again. If an object is no longer in use, you need to free the memory that the object occupies
Part 1. Basic memory management Model part 1.1 automatic garbage collection:
- The system can automatically Jatze if the object has other objects, and the object that is no longer referenced will be automatically freed when the program executes the required space.
Part 1.2 manually manages memory counts:
- The reference number +1 is required whenever a reference to an object is created.
[myFraction retain]
- When an object is no longer needed, send the release message to the object, which is the number of references-1.
[myFraction release]
- When the object's reference count is 0, the system knows that the object is no longer needed.
Part 1.3 Automatic reference count (ARC):
- The system detects when the object needs to be persisted, when the object needs to be freed automatically, and when the object is disposed.
Part 2. Autoreleasepool Block
for0; i < n; ++i){ @autoreleasepool{ ...临时对象... }}
Part 3. Time Loops and memory allocations
- To handle the new event, a new auto-release pool is created.
- Call some methods in the app to handle this event, and after the method returns, the system cleans up the auto-free pool.
- The automatically freed objects that are created are destroyed unless they are used to
retain
survive the process of emptying the pool automatically.
Part 4. Strong variables and weak variables
Strong variables:
- Pointers to all objects are strongly variable
- References to old objects are freed before they are assigned.
- Declaring objects:
__strong Fraction *f1
- Declaring attributes:
@property(strong, nonatomic) NSMutableArray *birdNames;
Weak variables
- The system will track the reference to this variable. When the referenced object is disposed, the variable is set to
nil
.
- Declaring objects:
__week UIView *parentView;
- Declaring attributes:
@property(week, nonatomic) UIView *parentView;
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
[Study note-OBJECTIVE-C] "OBJECTIVE-C Programming 6th Edition" chapter 17th memory management and automatic counting