美文网首页
内存监控

内存监控

作者: 一笔春秋 | 来源:发表于2019-10-25 13:30 被阅读0次
#import <mach/mach.h>

+ (long long)memoryUsage
{
    vm_size_t memory = memory_usage();
    SCDebugLog(@"当前占用内存:%ld",(long long)memory);
    return memory;
}


vm_size_t memory_usage(void) {
    struct task_basic_info info;
    mach_msg_type_number_t size = sizeof(info);
    kern_return_t kerr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size);
    return (kerr == KERN_SUCCESS) ? info.virtual_size : 0; // size in bytes
}

相关文章

网友评论

      本文标题:内存监控

      本文链接:https://www.haomeiwen.com/subject/rrysvctx.html