In UIViewController subclasses, I often see:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"Home", nil);
}
return self;
}
-
Why not set
self.titlein-viewDidLoad? -
Are all string literals always loaded into memory?
String literals are compiled into your executable file – they are not resources. They are kept in the initialized static data section in the executable. So yes, on the most basic level they are in memory whenever the executable is loaded – that is, whenever the program is running.
There is paging though. Somtetimes, when the memory runs low, it’s possible that the system throws parts of your running executable out of memory to free up some, and reloads them once they’re needed. This process is automatic, transparent, and unpredictable. So there’s a minor chance that the string is not physically in memory at some point in time, but once you try to access it, it will magically be there. Any paging is never done on per-string basis – it’s done in units of 4-8 KB (“pages”).