Today, I will briefly describe the simple memory management. After ios5.0, Apple added the arc mechanism (automatic reference counting), which brought a lot of convenience to developers, however, in order to better understand the IOS memory management mechanism, you still ne
Objects in 1.ObjC are stored in the heap, and the system does not automatically free up memory in the heap, but the base type is managed by the system itself and placed on the stack.2. It is not difficult to develop a program, but good programs weigh more heavily on memory management, which often consumes less memory a
];[Super Dealloc];}@end
Container Class (collection) memory management1, the object is added to the container, the container object will be a reference count of the reservation, that is, reference count +1 (that is, retain)2, remove the object from the container, the object reference count-1 (release)3. When the container object is release, all object references in the container are counted-1 (release).
Copy:to the System class (example:
This morning most of the time to review the contents of the study since the beginning of the school and explain yesterday's homework, yesterday's work in the realization of different Zomb scored different this function when the teacher skillfully use the value of self.speed to achieve different points, instead of assigning different tag last case The method of tag value to judge different zombies plus different scores is not usedif ([Z ISMEMBEROFCLASS:[ZOMBC class]]) method to judge different
UIViewController memory management for iOS development is described in this article. After iOS 3.0, UIViewController adds a method called viewDidUnLoad. Many people do not know the specific significance of this method. Apple's document simply explains "Called when the controller's view is released from
Block memory management of external variablesCode blocks are commonly used in iOS for callbacks, and this article focuses on the management mechanism of block to external variables. We know that if a variable outside the block is to be used in a block, if the variable is a local variable, it must be declared as the __b
) that calls the release method when the system feels it needs to be cleaned. Due to the system to deal with, so may release the moment is not so timely, so in some necessary time, we still need to manually go to release.Also a place to note is the container. Nsarray,nsdictionary These classes, when the object is added, the object's reference is automatically counted +1, and when it destroys itself, the reference count of these objects is 1. The same is true of the subview of UIView.Memory
Today, a BUG broke out in the company, leading to 5000+crash. Roughly, the delegate in UIKit visited the already released interface, which is the use of wild pointers to cause crash. Come back and demonstrate the discovery @property (nonatomic, assign) id Most of the UIKit's delegate are statements like 1. Because iOS doesn't have ARC before 5, it's written assign for compatibility. So what's the difference between assign and weak? __strong nsstring *
(block);[P release]; //Execute to line, people will not release, modify code: __block person *p = [[Person alloc]init]; you can release it .3> non-arc, a block property of a class, if you want to do this class of objects exist, block exists. This block attribute cannot be used with assign and must be copyA> because the block's memory is in the stack, it may be released at any time.B> with copy of the flower, block of
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 poolThe auto-free pool is an automatic memory recovery mechanism for OC, which can be used to collect temporary variables th
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 poolThe auto-free pool is an automatic memory recovery mechanism for OC, which can be used to collect temporary variables th
example, if we want a better method, we will declare such a category to implement it. Then you can directly use these better methods later.
In this case, we always think the category is a bit like an optional protocol.
The Optional Protocol is only a matter of foresight, and the category is a later remedy. When we work together, the method implementation is optional. The Optional Protocol has a key optionnal statement, And you declare the type as you do in an efficient way,
If you don't want.
A
the "advanced out" principle
#import
#import "Person.h"
int main (int argc, const char * argv[])
{
Auto Free Pool 1
@autoreleasepool {
Release of object to auto-release pool to manage no more writing [person release]
Person *person = [[[Person alloc] init] autorelease];
Then create an auto-release Pool 2
@autoreleasepool {
Person *person2 = [[[Person alloc] init] autorelease];
}
Person *person3 = [[[Person alloc] init] autorelease];
}
return 0;
auto-free pool is released.The above piece of code is a book, but it is good to illustrate the use of autoreleasepool, teachers often said that can not bookworm, should be more thinking, self-realistic examples, more questions, more discussionHere I put the thinking to write, for your reference:1.autoreleasepool can only put the objects in the pool function, we manually manage the memory it regardless, that is, manual or Automatic (System) two sets o
When we create an object with Alloc, new, and copy, the object's application count is 1, when the object is retain. Reference Count +1. When sending a release message to this object, reference count-1, when the object's reference count is 0 o'clock, the system recycles the object, when the pointer to this object is a wild pointer, to assign the wild pointer to nil, in addition, when the object reference count is 0 o'clock. The Dealloc method is called (self-overriding, in the end to invoke the [
One, assignRepresents the setting time to assign a value directly, rather than copying or preserving it.Two, retain.The new value is retained when the value is assigned. This property can only be used with Object-c object types.Three, copyWhen assigning a value, a copy of the new value is copied, and the copy is executed by copy, which is valid only for those object types that implement the Nscopying protocol.Reference: "The iphone and ipad development Combat-
I. PrincipleFor any object that inherits the NSObject, there is an shaping variable associated with it, called the reference counter, and only when the counter has a value of 0, OC reclaims the object, otherwise it is never recycled.1. When creating an object, such as using Alloc, new, copy, the value of the reference counter is 12. When released using the release method, the value of the counter is reduced by 13. When using the Retain method, the value of the counter is incremented by 14. When
variable, which is called the __block variable; __blockint temp=2; void ( ^myblk) () =^ () {temp+=8;};Myblk (); printf("----%d", temp); The value of an automatic variable intercepted by 2.2.5 can not be modified, but when an OC object (such as Nsmutablearray) is intercepted, it is possible to add elements to the array, and the direct assignment is not. That is, it can be used and cannot be assigned. To assign a value, you also need to add the __block modifier. When using C-language arrays, it
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.