Memory used by iPhone app

ios, ios5, iphone, memory

Solution

First include the method report_memory in the .h file then import

#import <mach/mach.h>

this to the .m file

After that write this line where you want to print the memory usage value

[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(report_memory) userInfo:nil repeats:YES];

then add this

-(void) report_memory {
    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 usage: %.4lf MB", info.resident_size/1024.0/1024.0);
    } else {
        NSLog(@"Error with task_info(): %s", mach_error_string(kerr));
    }
}

method to .m file

Problem

Possible Duplicate: How to Programmatically Tell How Much Memory an iOS App is Using? I need to know how much memory is used by an iPhone an application when the application is running in foreground or background. it will better if it shows memory useage in every 5 sec. is it possible to write a code to show the memory in use ? Any suggestion will be appriciated

Original source

Related problems