Arc of developer part1

867 views

Published on

Published in: Education, Technology, Business
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
867
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
14
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Arc of developer part1

  1. 1. ARC of a Developer Part.111 11 22
  2. 2. Automatic Referrence Counting • Objective-C • - • - retain release • - weak weak referrence11 11 22
  3. 3. • • • EXC_BAD_ACCESS •2 release • NSZombie • •11 11 22
  4. 4. ARC • GC • • retain/release 2.5 • autoreleasepool 6 • objc_msgSend 33%11 11 22
  5. 5. ARC •11 11 22
  6. 6. ARC • ARC • LLVM3.0 • -fobjc-arc11 11 22
  7. 7. • -fno-objc-arc11 11 22
  8. 8. • iOS4 weak reference • __unsafe_unretained • weak reference11 11 22
  9. 9. • __strong • __weak • __unsafe_unretained • __autoreleasing •11 11 22
  10. 10. Before ARC • • autorelease •11 11 22
  11. 11. • • VB6 • COM • Objective-C • • JAVA .NET Obj-C GC11 11 22
  12. 12. • NSObject *obj = [[NSObject alloc]init]; * obj NSObject 111 11 22
  13. 13. • NSObject *obj = [[NSObject alloc]init]; • NSObject *obj2 = [obj retain]; * obj NSObject 2 * obj211 11 22
  14. 14. • NSObject *obj = [[NSObject alloc]init]; • NSObject *obj2 = [obj retain]; • [obj release]; NSObject 1 * obj211 11 22
  15. 15. • NSObject *obj = [[NSObject alloc]init]; • NSObject *obj2 = [obj retain]; • [obj release]; • [obj2 release]; NSObject 011 11 22
  16. 16. Autorelease • +(id)array{ NSMutableArray *array = [[[NSMutableArray alloc]init]autorelease]; return array; } * array NSArray 111 11 22
  17. 17. Autorelease • +(id)array{ NSMutableArray *array = [[[NSMutableArray alloc]init]autorelease]; return array; } * array NSArray release 1 autorelease pool11 11 22
  18. 18. Autorelease • +(id)array{ NSMutableArray *array = [[[NSMutableArray alloc]init]autorelease]; return array; } NSArray release 1 autorelease pool11 11 22
  19. 19. Autorelease • +(id)array{ NSMutableArray *array = [[[NSMutableArray alloc]init]autorelease]; return array; } NSArray 011 11 22
  20. 20. Retain Release Autorerelease • •11 11 22
  21. 21. 11 11 22
  22. 22. • •11 11 22
  23. 23. Xcode Static Analyzer • Xcode Analyze •11 11 22
  24. 24. ARC • • Retain Release11 11 22
  25. 25. • __strong • __weak • __unsafe_unretained • __autoreleasing11 11 22
  26. 26. nil • nil • id __strong obj1; • id __strong obj1 = nil;11 11 22
  27. 27. __strong • • id • id test = [[NSObject alloc]init]; • id __strong test = [[NSObject alloc]init]; • retain release • strong11 11 22
  28. 28. __strong • dealloc release • release • Retain • Release11 11 22
  29. 29. __strong +1 +1 { NSMutableArray *array = [[NSMutableArray alloc]init]; [array addObject:[[NSObject alloc]init]]; [array addObject:[[NSObject alloc]init]]; [array addObject:[[NSObject alloc]init]]; [array addObject:[[NSObject alloc]init]]; } • array +1 • array -111 11 22
  30. 30. Retain { NSMutableArray *array = [[NSMutableArray alloc]init]; [array addObject:[[NSObject alloc]init]]; [array addObject:[[NSObject alloc]init]]; [array addObject:[[NSObject alloc]init]]; [array addObject:[[NSObject alloc]init]]; } @property (nonatomic,retain) NSMutableArray *array; { self.array = [[[NSMutableArray alloc]init]autorelease]; [array addObject:[[[NSObject alloc]init]autorelease]]; [array addObject:[[[NSObject alloc]init]autorelease]]; [array addObject:[[[NSObject alloc]init]autorelease]]; [array addObject:[[[NSObject alloc]init]autorelease]]; }11 11 22
  31. 31. Autorelease • Relase +1 +1 { NSMutableArray *array = [[NSMutableArray alloc]init]; [array addObject:[[NSObject alloc]init]]; [array addObject:[[NSObject alloc]init]]; [array addObject:[[NSObject alloc]init]]; [array addObject:[[NSObject alloc]init]]; }11 11 22
  32. 32. • autorelease • autorelease pool +(id)array{ id obj = [[NSMutableArray alloc]init]; return obj; }11 11 22
  33. 33. assign __unsafe_unretained copy __strong retain __strong strong __strong unsafe_unretained __unsafe_unretained weak __weak11 11 22
  34. 34. strong • release retain •11 11 22
  35. 35. 11 11 22
  36. 36. • A B C E D11 11 22
  37. 37. A B C E D11 11 22
  38. 38. A B C assign E D11 11 22
  39. 39. @interface Test : NSObject{ id childObject; } -(void)setObject:(id)child; @end { id test1 = [[Test alloc]init]; id test2 = [[Test alloc]init]; [test1 setObject:test2]; [test2 setObject:test1]; }11 11 22
  40. 40. { id test1 = [[Test alloc]init]; id test2 = [[Test alloc]init]; [test1 setObject:test2]; [test2 setObject:test1]; } test1 test2 test1 test211 11 22
  41. 41. __weak • Retain @interface Test : NSObject{ id __weak childObject; } -(void)setObject:(id)child; @end test1 test211 11 22
  42. 42. __weak • nil • test1 test211 11 22
  43. 43. __weak +1 id __weak obj = [[NSObject alloc]init]; • delegate11 11 22
  44. 44. autorelease pool • • Thread NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; // [pool drain]; @autoreleasepool { // } • LLVM3.0 ARC11 11 22
  45. 45. •11 11 22
  46. 46. 11 11 22

×