0

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
}
*/
tomfriwel
  • 2,575
  • 3
  • 20
  • 47

3 Answers3

0

NSUserDefaults is really meant for storing small pieces of data such as settings, preferences, and individual values.

Suggest using Core Data or SQLite to store a large list of elements.

There was a very good question about sqlite vs. Core Data; Working with data in iOS Apps and Core Data vs SQLite 3 on Stack Overflow, you may want to read through the answers to that question.

Community
  • 1
  • 1
liangju
  • 98
  • 1
  • 5
0

i thnik there is no size limit to storing in NSUserDefaults.It's all upon device storage.. you can check this link https://discussions.apple.com/thread/1763096?start=0&tstart=0

property lists should be used for data that consists primarily of strings and numbers. They are very inefficient when used with large blocks of binary data.

Dharma
  • 3,007
  • 3
  • 23
  • 38
0

Tom, There are many way in iOS to store the data.

1- NSUserDefault

2- Plist file

3- Data Base

If you have some small data then, NSUserDefaults and Plist is best option (no need to create database). But if you have a large amount of data then, i would suggest you to use a proper DataBase (Sqlite OR CoreData).

Parvendra Singh
  • 965
  • 7
  • 19