Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resident_size 大小问题 #14

Open
laughingkid opened this issue Jul 17, 2018 · 2 comments
Open

resident_size 大小问题 #14

laughingkid opened this issue Jul 17, 2018 · 2 comments

Comments

@laughingkid
Copy link

当内存一直增加,resident_size会停留在一个最大值(这个最大值会比resident_size_max小一点),然后不在增加.所以这个resident_size并不能真的代表app使用的内存.

用resident_size 去获取app的使用内存是不准确的.

@aozhimin
Copy link
Owner

@laughingkid 是的,resident_size 确实获取不到准确的内存,正确的方式是使用 phys_footprint,这个从 WebKit 和 XNU 的源码都能够得到佐证。WebKit 代码

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<size_t>(vmInfo.phys_footprint);
}

XNU 代码 中 Jetsam 中判断应用内存是否过大使用的也是 phys_footprint,2018 WWDC Session iOS Memory Deep Dive 对这块也有介绍,有兴趣可以去看下。

@aozhimin
Copy link
Owner

aozhimin commented Oct 13, 2018

详细的讨论过程见这个 Issue-获取 App 内存不准

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants