美文网首页工作生活
当前APP内存占用(转)

当前APP内存占用(转)

作者: 一笔春秋 | 来源:发表于2019-07-03 13:46 被阅读0次

    转自:https://www.cnblogs.com/miaocunfa/p/9661922.html

    #import <mach/mach.h>
    - (int64_t)memoryUsage {
        int64_t memoryUsageInByte = 0;
        task_vm_info_data_t vmInfo;
        mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
        kern_return_t kernelReturn = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);
        if(kernelReturn == KERN_SUCCESS) {
            memoryUsageInByte = (int64_t) vmInfo.phys_footprint;
            NSLog(@"Memory in use (in bytes): %lld", memoryUsageInByte);
        } else {
            NSLog(@"Error with task_info(): %s", mach_error_string(kernelReturn));
        }
        return memoryUsageInByte;
    }
    

    相关文章

      网友评论

        本文标题:当前APP内存占用(转)

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