Reputation: 3150
I must be missing something obvious, but how come that the following very simple app that creates 1000 1MB data objects and stores them in an array does work and does not seem to saturate (memory footprint of the app is shown as 1.7MB in Xcode)? This code was tested on an iPad 2 with 1GB of memory and does not crash.
@implementation AppDelegate {
NSMutableArray* datas;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
datas = [NSMutableArray new];
for (int i = 0; i < 1024; i++) {
[datas addObject:[NSMutableData dataWithLength:1024*1024]];
}
return YES;
}
@end
I guess that the question really is if some of the allocations are actually done on the iPad flash memory (instead of RAM), and if anybody has any more details about this?
Upvotes: 2
Views: 570
Reputation: 11713
Apple have always made the following statement about the iPhone Simulator:
Important: The simulator is great for debugging, but the ultimate arbiter of what will and won't work on iOS is a real device. It is especially important to keep this in mind when doing performance testing and debugging.
According to Apple Memory Usage Performance Guidelines:
If you do not plan to use a particular block of memory right away, deferring the allocation until the time when you actually need it is the best course of action. For example, to avoid the appearance of your app launching slowly, minimize the amount of memory you allocate at launch time.
So I am not sure if this is just an exercise to see how much memory you can alloc or not. But if it's a prototype for a future application, I would change the structure of your application and only load the information you need to display when you need it. Remember all data is living on a solid state device. You will not have the performance hit you would take with a standard spindle hard drive.
Upvotes: 3