Xcode app memory usage errors are unexplainable

I am using the following code to retrieve the amount of memory used by an application that I am running on my device:

-(void)appRam
{
    task_basic_info         info;
    kern_return_t           rval = 0;
    mach_port_t             task = mach_task_self();
    mach_msg_type_number_t  tcnt = TASK_BASIC_INFO_COUNT;
    task_info_t             tptr = (task_info_t) &info;

    memset(&info, 0, sizeof(info));

    rval = task_info(task, TASK_BASIC_INFO, tptr, &tcnt);
    if (!(rval == KERN_SUCCESS)) return 0;

    return info.resident_size;
}

      

However, the amount of memory returned is much larger than what Xcode shows in the debug navigator. For example, at some particular point, the method above returned 30MB, while Xcode only showed 8.2MB (see attached screenshot), I am looking to find the reason for this inconsistency and how to fix my method to return the exact amount of application usage memory. Anyone?

enter image description here

+3


source to share





All Articles