This simple question has always been told by five years of Apple development experience that it is not worth mentioning and there is nothing to mention.
However, today I have made a mistake that is not worth mentioning. For a long time, I think it is not worth mentioning. It is also a small mistake that is caused by the strangeness of my understanding.
The question is: traverse an array. If the conditions are met, add another array and remove it from the array to save storage space.
Analysis:
1. Because the addition and subtraction of the same object between arrays, this is only adding and dropping pointers. It only increases the reference count and does not increase the actual memory space allocation;
2. There is no problem with adding. The declared target array is NSMutableArray. When I subtract it, I use the delete method, but this method does exist;
Statement
NSArray *rows = [fileContent componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];NSMutableArray *geometryRows = [[NSMutableArray alloc] init];
Use
[geometryRows addObject:row];
[rows delete:row];
This error is made by using UIResponder and the delete method of this class is automatically prompted;
In fact, rows is NSArray and its elements cannot be edited. Just change them to the following:
NSMutableArray *rows = [NSMutableArray arrayWithArray:[fileContent componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]]];
However, at present, this question is just a question for finding a problem. Why? The reason is as follows:
1. Increasing the number is also to increase the reference count and pointer address of the original object. There will be no memory allocation for new copies of the original object content. Therefore, the attached memory allocation is very small and you do not need to consider it;
2. If the declared pointer does not exist and the content pointed to by the original pointer does not have a pointer index, the ARC will detect it during compilation, add the code for releasing memory for it, so there is no need to consider Memory leakage;
3. From this we can see that we have been worried about nothing, and it has caused so many cases of blood and wasted so much publicity. We hope that we can also make a difference to watch the world, do not commit multiple cases that result from a series of misunderstandings;
Click here!