2

Instruments' Allocations template tells the current memory usage of the app under 'All Allocations - Live Bytes'.

And according to this thread Programmatically retrieve memory usage on iPhone, I can also get the memory usage of the app using the following code:

#import <mach/mach.h>

// ...

void report_memory(void) {
  struct task_basic_info info;
  mach_msg_type_number_t size = sizeof(info);
  kern_return_t kerr = task_info(mach_task_self(),
                                 TASK_BASIC_INFO,
                                 (task_info_t)&info,
                                 &size);
  if( kerr == KERN_SUCCESS ) {
    NSLog(@"Memory in use (in bytes): %u", info.resident_size);
  } else {
    NSLog(@"Error with task_info(): %s", mach_error_string(kerr));
  }
}

But when 'Live Bytes' shows me 7+MB, the above code gives 40+MB. Aren't they supposed to be around the same?

Community
  • 1
  • 1

0 Answers0