I recently found that when I save, for example, 10MB data into user defaults and I relaunch app, the app's memory is larger about 10MB than previous launch according to Xcode memory report.
So I can't use NSUserDefaults
to save large data for a good performance?
And the data is email messages, have notion of folder (inbox, trash, etc) and the messages' attachments need save to local. I know SQLite
and I use it to store data that need for search, but it's some complex, I don't know whether CoreData
is a good choice.
I planned to store emails to NSUserDefaults
because it's very simple for I just implement NSCoding
protocol, but now it seems not good solution for the memory issue.
// Save
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:mailFolders];
[userDefaults setObject:data forKey:@"myKey"];
[userDefaults synchronize];
// Read
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSData *mailData = [userDefaults objectForKey:@"myKey"];
NSArray *mailDataArray = [NSKeyedUnarchiver unarchiveObjectWithData:mailData];
NSLog(@"mail data size:%@", [NSByteCountFormatter stringFromByteCount:mailData.length countStyle:NSByteCountFormatterCountStyleFile]);
/**
mailFolder {
folderInfo,
messages
}
*/