xcode里怎么看app占用了多少内存
推荐于2016-05-20 · 知道合伙人互联网行家
关注
展开全部
获取当前设备可用内存(单位:MB)
- (double)availableMemory
{
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn
= host_statistics(mach_host_self(),
HOST_VM_INFO,
(host_info_t)&vmStats,
&infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return ((vm_page_size * vmStats.free_count) / 1024.0) / 1024.0;
}
获取当前任务所占用的内存(单位:MB)
#include <sys/sysctl.h>
#include <mach/mach.h>
- (double)usedMemory
{
task_basic_info_data_t taskInfo;
mach_msg_type_number_t infoCount = TASK_BASIC_INFO_COUNT;
kern_return_t kernReturn = task_info(mach_task_self(),
TASK_BASIC_INFO, (task_info_t)&taskInfo, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return taskInfo.resident_size / 1024.0 / 1024.0;
}
- (double)availableMemory
{
vm_statistics_data_t vmStats;
mach_msg_type_number_t infoCount = HOST_VM_INFO_COUNT;
kern_return_t kernReturn
= host_statistics(mach_host_self(),
HOST_VM_INFO,
(host_info_t)&vmStats,
&infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return ((vm_page_size * vmStats.free_count) / 1024.0) / 1024.0;
}
获取当前任务所占用的内存(单位:MB)
#include <sys/sysctl.h>
#include <mach/mach.h>
- (double)usedMemory
{
task_basic_info_data_t taskInfo;
mach_msg_type_number_t infoCount = TASK_BASIC_INFO_COUNT;
kern_return_t kernReturn = task_info(mach_task_self(),
TASK_BASIC_INFO, (task_info_t)&taskInfo, &infoCount);
if(kernReturn != KERN_SUCCESS) {
return NSNotFound;
}
return taskInfo.resident_size / 1024.0 / 1024.0;
}
麦保(深圳)科技有限公司_
2023-03-28 广告
2023-03-28 广告
cleanmymac是我必装的mac端清理软件,界面简洁好看,完美适配mac系统,文件清理的速度、精度都比较优秀,还是比较不错的呢。cleanmymac作为一款第三方清洁应用程序,具有专业完整的清理功能,包括释放内存、一键智能扫描垃圾和缓存...
点击进入详情页
本回答由麦保(深圳)科技有限公司_提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询