Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cocoa - How to programmatically retrieve the amount of memory your application is using?

I would like to know how much memory my application is using. How would I be able to retrieve this programmatically? Is there an easy Cocoa way to do this, or would I have to go all the way down to C?

Thanks!

like image 334
Alex Avatar asked Jun 16 '11 10:06

Alex


1 Answers

Working snippet:

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));
}

Unfortunately I don't know the original source anymore.

like image 69
Anne Avatar answered Oct 15 '22 06:10

Anne