Reputation: 37581
Note: I'm not asking if there is a maximum, this question has been asked before, I'm asking if there is any minimum left in reserve for an app.
My app downloads packages of content from the internet and I'm investigation how it should behave in low/no disk space conditions.
The packages have a time element, and if there's no space then the app could automatically delete old content in order to make space for new content. (The packages can expire, so them being removed without the user explicitly deleting them is standard behavior).
However this is pointless if all diskspace is shared between all apps and some other app has gobbled up all the available disk space on the device such that there's nothing at all left for my app. Is this scenario possible where another app can consume everything leaving nothing for my app? Or is there some amount of space reserved per app?
Upvotes: 2
Views: 473
Reputation: 24248
Before writing on disk you could check amount of free disk space available and alert user accordingly.
-(uint64_t)getFreeDiskspacePrivate
{
uint64_t totalSpace = 0.0f;
uint64_t totalFreeSpace = 0.0f;
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
totalSpace = [fileSystemSizeInBytes floatValue];
totalFreeSpace = [freeFileSystemSizeInBytes floatValue];
//NSLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", ((totalSpace/1024ll)/1024ll), ((totalFreeSpace/1024ll)/1024ll));
} /*else {
NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %@", [error domain], [error code]);
}
*/
return totalFreeSpace;
}
Upvotes: 0
Reputation: 2203
AFAIK there is no actual limit. I've been working with an app which has a 1.6GB footprint, and have had no problems. Essentially you work with what is available, and if someone else is being mean and taking all the space, there is not much you can do about it. A good policy could be to state 'My app will use 512mb of space on disk' or something like that, and then ensure that you never exceed that. Which will give you piece of mind that your app works to an upper limit. Rule of thumb on any mobile device, never assume you have enough space for anything, always check for failures when writing to disk, and have a policy to deal with it.
Further to this. If you want to guarantee that your app will always have enough space. Pick an upper limit of size (say 256 mb), and on install and first run of your app, create dummy files that eat up that much space on disk. Then, as you download useful data, replace the dummy files with the useful ones so that your app is always using that original amount of reserved space.
It also seems i misunderstood the question a little. The minimum reserved for your app is the space it will take up on a fresh download from the app store. That's it. If you only have 200mb free and you try to download a 300mb app, it wont let you.
Upvotes: 0
Reputation: 8121
There is no limit on the amount of space an app can consume. An app could in theory use all the available disk space.
Upvotes: 1