iOS Classic interview will ask some questions: After more than half a month for everyone to sort out, some of the answers are not unique!
1, briefly describes the memory management mechanism in OC. The method used for pairing with retain is dealloc or release, why? The method that needs to be paired with Alloc is Dealloc or release, why? readwrite,readonly,assign,retain,copy , the role of Nonatomic, Atomic, strong, weak attributes?
Answer (1.) Memory management mechanism
A. Reference count because iOS does not have a garbage collection mechanism, iOS uses an app count to determine whether an object is released.
B. Change the reference count of the operation Alloc,retain,release,copy,dealloc, etc. (specific explanation to see the first question). Yu
C. Convenience Builder
D. Auto-release pool each time the object calls the Autorelease method (the formal argument in obj-c should be: The object sends a autorelease message), the object's reference count does not really change, but instead adds a record to the pool, noting the object's requirements. Finally, when the pool sends a drain or release message, this requirement for all objects in the pools is executed (that is, all objects in the pool are notified before the pooling is destroyed, and all the release messages are actually reduced by the reference count. If the object has previously sent a autorelease message)
E. Thread note When the view exits, you need to close the thread
Release-----, Alloc Open Space Deaclloc destruction space. When you call Dealloc manually, you are forced to set the reference count to 0
ReadWrite, readable writable, allows system to generate setter and getter ReadOnly , readable only, getter generated only
The Assign reference count is not +1 for the base data type. Often used to point to variables stored in static areas and delegate, directly assigned
Retain reference count +1 to get ownership of the object
Copy copies an object and stores it in a different memory area. The reference count of the original object does not change. Can be deep copy following the Nscoping protocol
nonatomic Non-atomic, does not guarantee the security of multi-thread protection Atomic atomicity, guaranteeing the security of multi-thread. There is one property that requires multiple threads to access a variable at the same time, using atomic to automatically lock and unlock.
Strong, used in Arc mode, indicates that the object belongs to a strong reference. Similar to retain, but
Retain is more secure, so long as the object exists, it can be referenced and will not be released. As long as the object loses its owner, it is immediately discarded. You do not have to point the pointer to an object that has already been disposed. Avoid the wild pointer.
Weak similar to assign, weak references. The app count does not increase. The release pointer automatically resets to nil;
2. Class variable @protected, @private, @public, @package, what is the meaning of the declaration?
Access member variables by way of
@protected protected. Methods in this class and in all subclasses can access such variables directly.
@private variable is private, the method of the class can directly access the variable. @public All classes can access
@package represents intra-frame access and cannot be accessed externally
3. What is a thread? What is a process? What are the differences and connections?
Thread, which is a concrete instance of the process. The minimum unit of program operation is the System independent dispatch and CPU basic operating unit. A process is a basic unit in the operating system that can work in parallel, an application that has a process, There is at least one thread in a process. The main difference between a process and a thread is that they are different ways to manage operating system resources. The process has a separate address space, and after a process crashes, it does not affect other processes in protected mode, and the thread is just a different execution path in a process. Thread has its own stack and local variables, but there is no separate address space between the threads, a thread dead is equal to the entire process dead, so the multi-process program is more robust than multithreaded programs, but in the process of switching, the cost of large resources, efficiency is worse. But for some concurrent operations that require simultaneous and shared variables, only threads can be used, and processes cannot be used
4. What is your understanding of multithreaded development? How many ways to implement multithreading in iOS?
In a process where multiple threads exist together, each thread performs its own task without interfering with one another, and a thread can create or revoke other threads. So that a process can perform many tasks at the same time. This reduces the waiting time,
iOS Classic face question