Http://aasheaa.blog.163.com/blog/static/99333120126311332613/
// Obtain the available memory and occupied memory of the current device # import <sys/sysctl. h> # import <Mach/mach. h> // obtain the available memory of the current device (unit: MB)-(double) availablememory {memory vmstats; interval infocount = Second; kern_return_t kernreturn = host_statistics (mach_host_self (), host_vm_info, (host_info_t) & vmstats, & infocount); If (kernreturn! = Kern_success) {return nsnotfound;} return (vm_page_size * vmstats. free_count)/1024.0)/1024.0;} // obtain the memory occupied by the current task (unit: MB)-(double) usedmemory {task_basic_info_data_t taskinfo; mach_msg_type_number_t infocount = task_basic_info_count; kern_return_t kernreturn = task_info (mach_task_self (), task_basic_info, (task_info_t) & taskinfo, & infocount); If (kernreturn! = Kern_success) {return nsnotfound;} return taskinfo. resident_size/1024.0/1024.0 ;}