Slide 1

Slide 1 text

Memory Management

Slide 2

Slide 2 text

-[NSObject retainCount]

Slide 3

Slide 3 text

Retainable Object Pointers

Slide 4

Slide 4 text

Object Pointers id Class NSObject __attribute__((NSObject))

Slide 5

Slide 5 text

__attribute__((NSObject))

Slide 6

Slide 6 text

dispatch_queue_t

Slide 7

Slide 7 text

@property (nonatomic, strong) dispatch_queue_t queue;

Slide 8

Slide 8 text

Ownership Qualification

Slide 9

Slide 9 text

__unsafe_unretained

Slide 10

Slide 10 text

__strong

Slide 11

Slide 11 text

__autoreleasing

Slide 12

Slide 12 text

__weak

Slide 13

Slide 13 text

id objc_storeWeak(id *object, id value)

Slide 14

Slide 14 text

objc_clear_deallocating

Slide 15

Slide 15 text

objc_arc_weak_unavailable

Slide 16

Slide 16 text

Property Declarations assign __unsafe_unretained copy -copy + __strong retain __strong unsafe_unretained __unsafe_unretained weak __weak

Slide 17

Slide 17 text

Blocks

Slide 18

Slide 18 text

`strong` vs `copy`

Slide 19

Slide 19 text

Always use copy

Slide 20

Slide 20 text

@property (nonatomic, copy)

Slide 21

Slide 21 text

dispatch_block_t block = ^{ NSLog(@"Hello World!"); }; ! NSArray *blocks = [[NSArray alloc] initWithObject:[block copy]];

Slide 22

Slide 22 text

Retain Cycle

Slide 23

Slide 23 text

- (void)startOperation { NSOperation *operation = [[NSOperation alloc] init]; ! [operation setCompletionBlock:^{ NSLog(@"Completion for %@", operation); }]; }

Slide 24

Slide 24 text

Operation Completion Handler

Slide 25

Slide 25 text

- (void)startOperation { NSOperation *operation = [[NSOperation alloc] init]; __weak NSOperation *weakOperation = operation; ! [operation setCompletionBlock:^{ NSLog(@"Completion for %@", weakOperation); }]; }

Slide 26

Slide 26 text

The Dealloc Problem

Slide 27

Slide 27 text

Releasing UIKit objects in background threads

Slide 28

Slide 28 text

CoreFoundation is not subject to ARC

Slide 29

Slide 29 text

CFRelease(stringRef);

Slide 30

Slide 30 text

UIColor *whiteColor = [UIColor whiteColor]; CGColorRef whiteRef = [whiteColor CGColor]; ! // Crash when using whiteRef

Slide 31

Slide 31 text

UIColor *whiteColor = [UIColor whiteColor]; CGColorRef whiteRef = CGRetain([whiteColor CGColor]); ! // Use whiteRef ! CGRelease(whiteRef);

Slide 32

Slide 32 text

Exceptions

Slide 33

Slide 33 text

-fobjc-arc-exceptions

Slide 34

Slide 34 text

Fast Enumeration

Slide 35

Slide 35 text

for (const __strong NSObject *object in objects) { NSLog(@”Object: %@”, object); }

Slide 36

Slide 36 text

Faster Enumeration

Slide 37

Slide 37 text

for (const __unsafe_unretained NSObject *object in objects) { NSLog(@”Object: %@”, object); }

Slide 38

Slide 38 text

Does this actually have any real world benefits?

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

KFNumber

Slide 41

Slide 41 text

Tagged Pointer

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

Twitter: @kylefuller GitHub: kylef ! http://kylefuller.co.uk/