Graphics Programs Reference
In-Depth Information
• If a pointer owns a Core Foundation object, you must call CFRelease before
you lose that pointer. Remember that a pointer can be lost if it is set to point at
something else (including nil ) or if the pointer itself is being destroyed.
• Once you call CFRelease on a pointer, you cannot access that pointer again.
As you can see, the rules of memory management are a bit more complicated when deal-
ing with Core Foundation because you don't have the luxury of ARC. However, you typ-
ically won't use Core Foundation objects as much as Objective-C objects. As long as you
stick to these rules, you will be okay.
Now, back to the __bridge keyword. ARC doesn't know how to manage memory with
Core Foundation objects very well, so it gets confused if you typecast a Core Foundation
pointer into its Objective-C counterpart. Placing __bridge in front of the cast tells
ARC, “Hey, don't even worry about it.” Thus, when ARC sees this line of code, it doesn't
give ownership to the key variable as it normally would:
NSString *key = (__bridge NSString *)newUniqueIDString;
Once key is an Objective-C pointer, ARC can do its work as normal. When this object is
passed to setImageKey: , BNRItem 's imageKey instance variable takes ownership
of that object.
Wrapping up BNRImageStore
Now that the BNRImageStore can store images and BNRItem s have a key to get that
image ( Figure 12.11 ) , we need to teach DetailViewController how to grab the im-
age for the selected BNRItem and place it in its imageView .
Figure 12.11 Cache
 
Search WWH ::




Custom Search