0

Hi i would like to know what is diff b/w @autorleasepool and release and both are using for decreasing retain count then what is diff b/w both of them and i wrote below two cases what happen both of this cases can some one explain me please...

case1:-

-(void)sendMessage{
@autoreleasepool{
NSString *name1 =[NSString alloc]init];
NSString *name2 =[NSString alloc]init];
  }
}

case2:-

-(void)sendMessage{
NSString *name1 =[NSString alloc]init];
NSString *name2 =[NSString alloc]init];
[name1 release];
[name2 release];
}
Krish
  • 4,166
  • 11
  • 58
  • 110
  • @Hi Rob i am not able write [name1 release]; statement in ViewDidLoad method why? – Krish Jul 18 '17 at 05:40
  • Likely because you are using "automatic reference counting" (ARC), which eliminates the hassles of needing to manually `autorelease` and `release` in your code. See [Transitioning to ARC Release Notes](https://developer.apple.com/library/content/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html) which describes how ARC takes care of all of this for you. It is exceeding usual to use manual reference counting (i.e. to not use ARC) nowadays. ARC is enabled by default (though you can control this in your app's target's "Build Settings"). – Rob Jul 18 '17 at 05:41
  • ok your mean no need to write [name1 release]; because Arc by default enables now a days right? – Krish Jul 18 '17 at 05:49
  • Yes, ARC takes care of inserting all of those `retain`, `release`, and `autorelease` calls for you. Nowadays you don't worry about that, but instead focus on "object ownership" (as outlined in the [Advanced Memory Management Programming Guide](https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/MemoryMgmt.html)). – Rob Jul 18 '17 at 05:51
  • ok thanks for your suggestions – Krish Jul 18 '17 at 05:54

0 Answers0