I am getting available memory from below method:
static void print_free_memory () {
float totalSpace = 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];
totalSpace = [fileSystemSizeInBytes floatValue];
NSLog(@"Total memory:%f",totalSpace);
freeMemAvailable = [[dictionary objectForKey:NSFileSystemFreeSize] floatValue];
NSLog(@"Free Memory:%f",freeMemAvailable);
} else {
NSLog(@"Error Obtaining File System Info: Domain = %@, Code = %@", [error domain], [error code]);
}
}
Above method returns = 9139.650391 mb ~ 9.14 GB
AND on Device memory displayed on the Device = 8.4 GB
Approximately, 700 MB difference. Why is it so? Any suggestions.
The path that I used to view the device memory on device is as follows.
Go to :- Settings -> General -> About -> Available
Your calculations are not precise the function return the size in bytes so assume the returned value was
9139650391you will need to divide it bu(1024*1024*1024)=1073741824so
9139650391/1073741824equals approximately 8.5 GB and not 9.14 GBabout the 100 MB difference, there is still a difference but not as big as 700MB