【问题标题】:How to get available memory in IOS ? [duplicate]如何在 IOS 中获取可用内存? [复制]
【发布时间】:2012-05-25 19:23:28
【问题描述】:

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

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

我用谷歌搜索,然后我知道如何在 VM 中获取物理内存、用户内存和使用的内存、释放内存。

但是。内存大小不同,设置->常规->关于->可用。

我想知道“设置”中的“可用”。

祝你有美好的一天。

【问题讨论】:

  • 我想你的意思是“可用存储”——stackoverflow.com/a/8036586/603256
  • 以下对您有用吗? stackoverflow.com/questions/5012886/…
  • 哦。我知道了。这是正确的。 “可用存储空间”......但还有一个问题。我得到了该方法背后的“可用存储”使用,但有点不同..总是 200MB 或 160MB。为什么 .. ?帮帮我..

标签: ios memory


【解决方案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;
}

【讨论】:

    猜你喜欢
    • 2017-01-26
    • 1970-01-01
    • 2018-12-10
    • 2010-10-10
    • 1970-01-01
    • 2014-07-17
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    相关资源
    最近更新 更多