Programmatically retrieve memory usage on iPhone

前端 未结 9 813
迷失自我
迷失自我 2020-11-22 16:56

I\'m trying to retrieve the amount of memory my iPhone app is using at anytime, programmatically. Yes I\'m aware about ObjectAlloc/Leaks. I\'m not interested in those, only

9条回答
  •  逝去的感伤
    2020-11-22 17:34

    Objective-C version:

    size_t memoryFootprint()
    {
        task_vm_info_data_t vmInfo;
        mach_msg_type_number_t count = TASK_VM_INFO_COUNT;
        kern_return_t result = task_info(mach_task_self(), TASK_VM_INFO, (task_info_t) &vmInfo, &count);
        if (result != KERN_SUCCESS)
            return 0;
        return static_cast(vmInfo.phys_footprint);
    }
    

提交回复
热议问题