First address of this article
1: What is the nature of MRC? Usually they say who files, who gets released. That’s true. But what is the nature of asking? Let’s start with the essence of ARC: the compiler automatically adds memory management code during compilation, so how does it manage? So how does this code manage? If you have a hashMap globally, you put variables and reference counts in it, and when you cross the reference field, the reference count is automatically returned to 0. But the object will be freed.
2: Before the block is executed, modify the variable. When is the value of the variable retrieved in the block? What is the use of weak there is no doubt that the variable was last assigned to the data. First, blocks are allocated to the stack area. Copy must be used first. So its scope is in the current context that you create, and when you call that block outside of that scope, the program crashes. But we don’t have to manually reain or release when we use blocks. That is, copy is only needed when a block is out of scope. It’s copying from the stack to the heap. It doesn’t crash when it’s done.
3: Write multiple [self dosomathing1],[self dosomathing2],[self dosomathing3],,,, To avoid putting a strong self in the block first. The idea is to avoid the possibility of self being released during block execution. If you’re holding self, but you don’t have a circular reference, when you’re done with the block, if there’s no other object holding it, the block is released, and bolck won’t hold self anymore. Same thing as uiView’s animation block
3: The principle of “weak” and “strong”? I personally think it is better to use strong because there is no special advantage in using weak. In addition, as we have seen in the last interview essay, the weak variable has extra system maintenance costs. If you do not have a special reason to use it, it is better to use strong. Another reader mentioned that if you want to load Lazy, you can only use strong. Of course, if you want to use weak, there is no problem, just be careful to add this object to the parent view with addSubView before assigning, otherwise it will be released as soon as it is created. In my mind, this is the interview question I like. There is no standard answer, and each scheme has its own characteristics. The interviewer can clearly distinguish the advantages and disadvantages of each scheme and make a choice based on specific scenarios.
4: How does the child thread return to the main thread? Runloop 1: The child thread returns to the main thread because it cannot update the UI. I don’t know the implementation 2: there are frameworks like UIKit to ensure thread safety. The child thread cannot update the UI, and if both the child thread and the main thread update the UI, it may crash the program. That’s releasing the object twice. Even if it doesn’t crash, it will mess up the UI. That’s putting the UI operator on the main thread. Because the response to events is just more timely, you don’t feel the change at all. Updates to the UI should wait until the child thread finishes running. That’s a short amount of time, so if the child thread keeps running to update the UI, the main thread can’t get it, but it can’t update it. If you make a button to click to change the background and the image is waiting to change the background, if you see the pause of the time he is waiting, then the response is not necessary. 3: thread and runloop are one-to-one 5: system memory is divided into several areas 1: stack area: local variables, and function parameters 2: heap area: open memory objects such as: alloc, new. This is the memory management area 3: constants, static area: places consist and static modified objects
If have wrong still instruct please !!!! Learn together and make progress together.
You can come to the wechat public number (Zhouzhouge) backstage to leave us a message. Scan the code to pay attention to us!