如何在IOS中获得可用内存?

时间:2012-05-18 08:01:12

标签: ios memory

  

可能重复:
  How to get information about free memory and running processes in an App Store approved app? (Yes, there is one!)

如何在IOS中获取可用内存?我不知道..

我用谷歌搜索,然后我知道如何在虚拟机中获取物理内存,用户内存和使用的内存,免费内存。

但是。内存大小不同,设置 - >一般 - >关于 - > Avaliable。

我想知道" Avaliable"在设置中。

祝你有个愉快的一天。

1 个答案:

答案 0 :(得分:1)

几个月前在这里发现了这个,不记得最初发布的人。这是你在找什么?

- (uint64_t)freeDiskspace
{
uint64_t totalSpace = 0;
uint64_t totalFreeSpace = 0;

__autoreleasing 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 unsignedLongLongValue];
    totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
    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;
}