I have been working on a game which using much image resources. One issue I am having with the cached and non-cached resources of UIImage.
In my game, there are almost 100 images display on a board, each image is my custom UIImageView. One of the requirements is to switch current images to others during the rotation animation. And here is what I did:
- Loop through all 100 UIImageView objects, make it rotate using CAKeyframeAnimation.
- While the rotation animation executing, load the new image (UIImage) using [UIImage imageNamed:] method to load new image, this new image will be cached
- Then call UIImageView.image=myNewImage to replace new loaded image
It works very smoothly, but the image resources are cached and my app holds too much memory. And I want to not using the system cached like that. I then not using [UIImage imageNamed:] method anymore but using the [UIImage imageWithContentsOfFile:] method instead. But the performance turns out even worse The new images are supposed to replace the old ones during the rotation, but the speed of loading new images is longer the rotation time. And you can imagine that the rotation animation stopped but the old images are still remained and it keep replacing one by one...
And my questions are:
1. Does anyone know why not using cache take more time to load image? While using cached, I am sure that all images are first loaded and not be reusing, the speed is way faster.
2. Is there any way to clear the system cached? As I don't need to reuse any of them in my app.
Your comments/feedback are appreciated.
In my game, there are almost 100 images display on a board, each image is my custom UIImageView. One of the requirements is to switch current images to others during the rotation animation. And here is what I did:
- Loop through all 100 UIImageView objects, make it rotate using CAKeyframeAnimation.
- While the rotation animation executing, load the new image (UIImage) using [UIImage imageNamed:] method to load new image, this new image will be cached
- Then call UIImageView.image=myNewImage to replace new loaded image
It works very smoothly, but the image resources are cached and my app holds too much memory. And I want to not using the system cached like that. I then not using [UIImage imageNamed:] method anymore but using the [UIImage imageWithContentsOfFile:] method instead. But the performance turns out even worse The new images are supposed to replace the old ones during the rotation, but the speed of loading new images is longer the rotation time. And you can imagine that the rotation animation stopped but the old images are still remained and it keep replacing one by one...
And my questions are:
1. Does anyone know why not using cache take more time to load image? While using cached, I am sure that all images are first loaded and not be reusing, the speed is way faster.
2. Is there any way to clear the system cached? As I don't need to reuse any of them in my app.
Your comments/feedback are appreciated.