Programmatically retrieve memory usage on iPhone

前端 未结 9 942
迷失自我
迷失自我 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:31

    Below is the correct answer:

    ```

    float GetTotalPhysicsMemory()
    {
        struct task_basic_info info;
        mach_msg_type_number_t size = sizeof(info);
        kern_return_t kr;
        kr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size);
        if (kr == KERN_SUCCESS) 
            return (float)(info.resident_size) / 1024.0 / 1024.0;
        else
            return 0;
    }
    

    ```

提交回复
热议问题