Created
June 12, 2012 00:14
-
-
Save RandyMcMillan/2913571 to your computer and use it in GitHub Desktop.
iOS Memory usage reporting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { | |
//NSLog(@"RECIEVED MEM WARNING WHY?"); | |
[self report_memory]; | |
[[NSURLCache sharedURLCache] removeAllCachedResponses]; | |
} | |
-(void) report_memory { | |
//#import "mach/mach.h" ///Add to headers | |
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)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment