1.先导入:
#import <mach/mach.h>
2.写此方法.单位为兆(M)。
void report_memory(void) { struct task_basic_info info; mach_msg_type_number_t size = sizeof(info); kern_return_t kernr = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&info, &size); if (kernr == KERN_SUCCESS) { printf("MEMORY IS :%f ", info.resident_size/(1024.0 * 1024.0)); } else { printf("MEMORY ERROR:%s ", mach_error_string(kernr)); } }
3.在想查看的敌方调用此方法:
report_memory();
4.在.pch文件中定义可全项目使用;
#ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import <CoreData/CoreData.h> #endif extern void report_memory(void);