Hope this help.
I also use the ALAsset, and I encountered memory warning. I'm still searching my solution for my app... The crash may be because iOS dealloc your view or objects because of memory warning. So, maybe preventing from memory warning is important. Keep peak memory low to bellow 30MB. I encountered memory warning for 50MB for ipad2 and didn't get it from iphone4. Anyway, lower is the better.
First of all,you can measure the memory
by using instrument or the following code. It's easier measure memory in code for logging.
1. register a timer for repeatedly report memory usage, you can see the peak memory usage in this way.
On other hand, I have no idea why this function will increase memory graduately.
2. "iPhone Programming The Big Nerd Ranch Guide" book said iOS may have 24MB for graphical memory
"Overuse of graphical memory is typically the reason why an application receives a low-memory warning. Apple suggests that you don’t use more than 24 MB of graphics memory. For an image the
size of the iPhone screen, the amount of memory used is over half a megabyte. Each UIView, image, Core Animation layer, and anything else that can be displayed on the screen consumes some of the allotted 24 MB. (Apple doesn’t suggest any maximum for other types of data like NSStrings.)"
So, review graphical memory usage.
NSTimer * timeUpdateTimer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(reportMem) userInfo:nil repeats:TRUE];
[[NSRunLoop mainRunLoop] addTimer:timeUpdateTimer forMode:NSDefaultRunLoopMode];
-(void) reportMem{
[self report_memory1];
}
-(void) report_memory1 {
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);
natural_t freem =[self get_free_memory];
if( kerr == KERN_SUCCESS ) {
NSLog(@"Memory in use %f %f(free)", info.resident_size/1000000.0,(float)freem/1000000.0);
} else {
NSLog(@"Error with task_info(): %s", mach_error_string(kerr));
}
}
-(natural_t) get_free_memory {
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
host_page_size(host_port, &pagesize);
vm_statistics_data_t vm_stat;
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) != KERN_SUCCESS) {
NSLog(@"Failed to fetch vm statistics");
return 0;
}
/* Stats in bytes */
natural_t mem_free = vm_stat.free_count * pagesize;
return mem_free;
}