I have an application that caches large images so that the user does not wait for imageWithContentsOfFile. Typically, I cache the previous and next image.
1) Can I make this caching adaptive based on the available memory in the iPad? If so, what should be the threshold? Below is the function for calculating available memory
-(void) report_memory { 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 ) { Log(@"Memory in use (in bytes): %u", info.resident_size); } else { Log(@"Error with task_info(): %s", mach_error_string(kerr)); } }
2) I know that there is no way (except for the private / undocumented API) to know the memory level warning, otherwise this can be a good factor for determining how many pages I can cache. But just to confirm if I can use them in any way.
3) Now I am thinking of caching 3 screens (which have 6 images), and if my ViewController receives a warning about memory, I unload all the screens except the visible one, and reset the number of screens for caching to 2 (4 images). But I do not think it is optimized, because either I cache less than possible, or in some conditions even loading 4 leads to a failure.
source share