Automatic release of the tank for weight-taking function
1 @autoreleasepool {2 UIView *view = [UIView alloc] init] autorelease]; 3 [view autorelease]; 4 }
This is written in the queue of the auto-free pool is two objects or an object, that is, when the view is added to the auto-free pool queue, the queue itself is the content of the weight
Prevents the object from being repeatedly added, compares the view inside the queue, and again calls Autorelease when there is no effect.
So I wrote a test code.
1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) Launchoptions2 {3Self.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];4 //Override point for customization after application launch.5Self.window.backgroundColor =[Uicolor Whitecolor];6 [Self.window makekeyandvisible];7 8UIView *view =[[[ UIView alloc] init] autorelease];9NSLog (@"%d", view.retaincount);Ten [view autorelease]; One A returnYES; -}
No crashes after running, stating that the auto-free pool itself is a heavy-weight feature and does not repeatedly add objects.
Auto-release Pool in iOS