Q&A Session 3: iOS Memory Management and Best Practices
In this week's Q&A session, Mark Hammonds answers questions left on Axit Patel's post "Working with the UITableView Class, Part 2." Specifically, this Q&A discusses memory management techniques and the ability to "autorelease" objects. Mark also talks about best practices when using viewDidLoad and other tips related to NSString.
1) In order to fill the imagesArray you create a couple of UIImageViews, but you don't release them later. Is this okay or did you just forget to do it?
2) Why do you create the dummy arrays anyway? Couldn't you just say self.sitesArray = [[NSArray alloc] initWithObjects:@"..", ... , nil]; ?
Or is there a reason to do it the way you did?
- At 6:40 in the video I state that using @"Hello World!" will return an auto-released string. This is incorrect. It is instead a statically allocated string that is kept around throughout the program lifecycle, as pointed out in the comments section below.
- At 7:31 I state that %@ is the format specifier for an NSString. Technically, this is correct, but it is important to note that %@ is also used to print information on other Cocoa-Touch objects as well. An object formatted with %@ will use the -description instance method originally inherited from
NSObjectto display custom output for that object. NSString implements this to display the string value, other objects behave in different ways.